Flutter:如何使用Firebase PhoneNumberAuth修复设备丢失的连接错误

Flutter:如何使用Firebase PhoneNumberAuth修复设备丢失的连接错误,第1张

Flutter:如何使用Firebase PhoneNumberAuth修复设备丢失的连接错误

pop
删除顶级窗口小部件。不确定在此之后加上逻辑是一个好主意。最好重新安排代码,例如

  // only gets SMS, no functionality  Future<String> getSmsCode(BuildContext context) {    return showDialog<String>(      context: context,      barrierDismissible: false,      builder: (BuildContext context) {        return alertDialog(          title: Text('SMS 코드를 입력해주세요'),          content: TextField( onChanged: (value) {   this.smsCode = value; },          ),          contentPadding: EdgeInsets.all(10),          actions: <Widget>[ FlatButton(   child: Text('Done'),   onPressed: () {     Navigator.of(context).pop(this.smsCode);   }, )          ],        );      },    );  }  SIGNIn() async {    String smsCode = await getSmsCode(context);    if (smsCode != null && !smsCode.isNotEmpty) {      print('User cancelled SMS dialog');      return;    }    final AuthCredential credential = PhoneAuthProvider.getCredential(      verificationId: verificationId,      smsCode: smsCode,    );    print('진행중');    FirebaseAuth _auth = FirebaseAuth.instance;    final FirebaseUser user = (await _auth.signInWithCredential(credential)).user;    final FirebaseUser currentUser = await _auth.currentUser();    assert(user.uid == currentUser.uid);    setState(() {      if (user != null) {        print('success!');      } else {        print('sign in failed');      }    });  }

现在仅调用

SIGNIn
,它将首先获取SMS代码,然后使用该SMS代码登录。希望能帮助到你。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4926710.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存