【问题标题】:how to extract the contents of the array?如何提取数组的内容?
【发布时间】:2019-05-26 07:51:20
【问题描述】:

我正在编写一个关于颤振的应用程序,但在提取 firebase 类的内容时我有点卡住了。如何从“用户”中提取 PhoneNumber 变量的内容?我需要将提取的号码发送到服务器

这是 debugPrint('user: $user') 的输出:

user: FirebaseUser({uid: hGLEDW6OT5ZMhWra9L4p6bB4Pw92, isAnonymous: false, phoneNumber: +79644054946, providerData: [{uid: hGLEDW6OT5ZMhWra9L4p6bB4Pw92, phoneNumber: +79644054946, providerId: firebase}], providerId: firebase, creationTimestamp: 1557420327980, lastSignInTimestamp: 1558848790729, isEmailVerified: false} 
void _signInWithPhoneNumber() async {
    final AuthCredential credential = PhoneAuthProvider.getCredential(
      verificationId: _verificationId,
      smsCode: _smsController.text,
    );
    final FirebaseUser user = await _auth.signInWithCredential(credential);
    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.uid == currentUser.uid);
    debugPrint('user: $user');
    setState(() {

      if (user != null) {

           Navigator.pushNamed(context, '/amenities');
      } else {
        _message = 'Вход не выполнен';
      }
    });
}

我需要从“用户”中提取 PhoneNumber 以发送到 Json 中的服务器

【问题讨论】:

  • user.providerData()[0].getPhoneNumber(); // 不要硬编码数组索引。运行必要的检查。

标签: firebase flutter dart firebase-authentication


【解决方案1】:

我很确定您可以通过 user.phoneNumber 获取电话号码

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    • 2017-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多