Firebase 颤振:如何实现回调
如何实现回调并返回错误消息? AuthService类的登录函数:Firebase 颤振:如何实现回调,firebase,flutter,dart,Firebase,Flutter,Dart,如何实现回调并返回错误消息? AuthService类的登录函数: static void login(String email, String password) async { try { await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password); } catch (e) { print(e); } } 从登录类提交函数
static void login(String email, String password) async {
try {
await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
} catch (e) {
print(e);
}
}
从登录类提交函数:
_submit() {
// If fail to login then return the error message
AuthService.login(_email, _password);
}
请尝试以下操作:
Future<AuthResult> login(String email, String password) async {
try {
Future<AuthResult> result = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
return result;
} catch (e) {
print(e);
}
}
方法使用Email和Password登录
返回未来
_submit() {
// If fail to login then return the error message
login(_email, _password).then((result) => {
print(result);
});
}
// wrapping the firebase calls
Future<FirebaseUser> loginUser({String email, String password}) {
return FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password);
}
userInfo = await AuthService().loginUser(email: _email, password: _password);