【发布时间】:2019-12-01 02:56:39
【问题描述】:
我正在尝试将电话身份验证系统集成到我的颤振应用程序中。但即使我输入了错误的 OTP,用户也会得到验证并进入下一页。
我正在使用对话框来请求 OTP
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return new AlertDialog(
title: Text('Enter sms Code'),
content: TextFormField(
controller: _smsController,
keyboardType: TextInputType.number,
textInputAction: TextInputAction.done,
decoration: InputDecoration(
hintText: 'Enter OTP', icon: Icon(Icons.perm_phone_msg)),
maxLength: 6,
maxLengthEnforced: true,
),
contentPadding: EdgeInsets.all(10.0),
actions: <Widget>[
new RaisedButton(
child: Text('Login'),
textColor: Colors.white,
onPressed: () {
_signInWithPhoneNumber(context);
})
],
);
});```
```void _signInWithPhoneNumber(BuildContext context) async {
final AuthCredential credential = await PhoneAuthProvider.getCredential(
verificationId: _verificationId,
smsCode: _smsController.text,
);
await _auth
.signInWithCredential(credential)
.then((FirebaseUser user) async {
final FirebaseUser currentUser = await _auth.currentUser();
assert(user.uid == currentUser.uid);
Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => InfoScreen(_phoneNumberController.text)));
}).catchError((e) {
print(e.message);
Navigator.of(context).pop();
});
}
}```
【问题讨论】: