chr*_*788 3 asynchronous async-await dart flutter
我正在为我的应用程序构建用户身份验证模块,并且遇到了一些异步代码的麻烦。
首先,这是引发的错误:
E / flutter(17162):[错误:flutter / shell / common / shell.cc(188)] Dart错误:未处理的异常:E / flutter(17162):'dart:async / future_impl.dart':断言失败:行146:“已优化”:不正确。E / flutter(17162):#0 _AssertionError._doThrowNew(dart:core / runtime / liberrors_patch.dart:40:39)E / flutter(17162):#1 _AssertionError._throwNew(dart:core / runtime / liberrors_patch.dart: 36:5)E / flutter(17162):#2 _FutureListener.handleError(dart:async / future_impl.dart:146:14)E / flutter(17162):#3 Future._propagateToListeners.handleError(dart:async / future_impl。 dart:654:47)E / flutter(17162):#4 Future._propagateToListeners(dart:async / future_impl.dart:675:24)E / flutter(17162):#5 Future._completeError(dart:async / future_impl。 dart:494:5)E / flutter(17162):#6 _SyncCompleter。_completeError(dart:async / future_impl.dart:55:12)E / flutter(17162):#7 _Completer.completeError(dart:async / future_impl.dart:27:5)E / flutter(17162):#8 _AsyncAwaitCompleter。 completeError(dart:async / runtime / libasync_patch.dart:40:18)E / flutter(17162):#9 FirebaseAuth.signInWithEmailAndPassword(package:firebase_auth / firebase_auth.dart)E / flutter(17162):E / flutter(17162) :#10 Session.login。(package:mood_map / utilities / session.dart:31:24)E / flutter(17162):#11 _RootZone.runUnary(dart:async / zone.dart:1379:54)E / flutter(17162):#12 _FutureListener .handleValue(dart:async / future_impl.dart:129:18)E / flutter(17162):#13 Future._propagateToListeners.handleValueCallback(dart:async / future_impl.dart:642:45)E / flutter(17162):# 14 Future._propagateToListeners(dart:async / future_impl.dart:671:
这里是涉及的功能:
static final FirebaseAuth _authenticator = FirebaseAuth.instance;
static void login(BuildContext context, String email, String password) async {
email = email.trim();
password = password.trim();
//Check if the user already exists
await _checkUserAlreadyExists(email).then((exists) {
if(exists) {
_authenticator.signInWithEmailAndPassword(email: email, password: password)
.then((FirebaseUser user) { _loginSuccess(); })
.catchError((Error e) { _loginFailure(context); });
} else {
Utilities.showMessageDialog(context, "That user doesn't exist. Please create an account below.");
}
});
}
----------------------------------------------------------------------
static Future createUserAccount(BuildContext context, email, String password) async {
//Check if the user already exists
await _checkUserAlreadyExists(email).then((exists) {
if(exists) {
Utilities.showMessageDialog(context, "That user already exists. Please login or select another account.");
AppNavigator.navigateToLoginScreen();
} else {
_authenticator.createUserWithEmailAndPassword(email: email, password: password)
.then((FirebaseUser user) { _createUserSuccess(); })
.catchError((Error e) { _createUserFailure(context); });
}
});
}
Run Code Online (Sandbox Code Playgroud)
简而言之,对_authenticator.signonWithEmailAndPassword()的调用失败。我知道_authenticator实例正在与其他功能一起使用,因此我知道Firebase本身不是问题。
我担心通过从另一个异步函数_checkIfUserAlreadyExists()中调用另一个异步函数_authenticator.signonWithEmailAndPassword()来做错事情。从我阅读的.then()块中似乎应该可以这样做,但是错误消息似乎非常坚持认为这与函数调用的异步性质的设置有关。
有什么想法吗?
| 归档时间: |
|
| 查看次数: |
1759 次 |
| 最近记录: |