【发布时间】:2020-07-17 19:58:45
【问题描述】:
首先我是 Flutter 的新手,我阅读了很多线程但没有得到任何东西。
我的问题是什么?
我有两个页面 auth.dart 和 login.dart。在 auth.dart 页面中我有一个名为 AuthService 的类 由以下代码组成(直截了当):
class AuthService {
final FirebaseAuth _auth = FirebaseAuth.instance;
Future<bool> signInWithPhone(String phone, BuildContext context) async {
....
verificationFailed: (AuthException exception) {
// i can see the exception in debug console using print
return exception;
},
....
}
}
在 login.dart 中,我有一个有状态的小部件,它看起来像这样,在那里我引用了上面的类,我正在调用 signInWithPhone 方法: p>
class LoginScreen extends StatefulWidget {
@override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final AuthService _auth = AuthService();
....
....
Container(
width: double.infinity,
child: FlatButton(
child: Text("LOGIN"),
textColor: Colors.white,
padding: EdgeInsets.all(16),
onPressed: () {
// here i am calling the method signInWithPhone of above class
final phone = _phoneController.text.trim();
_auth.signInWithPhone(phone, context);
}
)
)
....
....
}
我想要什么?
我想显示在我的登录按钮的 onPressed 事件中收到的异常错误消息,以便我可以使用错误消息显示警报对话框。
我尝试了什么?
1) print(_auth.signInWithPhone(phone, context)); 但它返回null;
2)
_auth.signInWithPhone(phone, context).then((value){
// alert/text/print
print(value);
}
这也返回 null
任何人都可以帮我解决它,因为如果手机号码不正确或 OTP 不正确,我需要向用户显示错误消息。
【问题讨论】:
标签: firebase flutter dart firebase-authentication