我正在为我的大学项目制作一个Flutter应用程序,在其中添加登录和注册页面并通过Firebase对其进行身份验证,并且当我单击登录时,调试控制台会显示“错误类型'AuthResult'不是类型'的子类型FirebaseUser'类型转换”,并且在此错误后我重新加载应用程序时,它将成功登录。
一切工作的的更新之前最好firebase_auth此更新后包0.12.0,方法“signInWithEmailAndPassword()”和“createUserWithEmailAndPassword()”引发错误“类型‘AuthResult’的值不能被分配给一个类型“FirebaseUser”的变量。尝试改变变量的类型,或铸造右手型为“FirebaseUser””,所以我增加了一个铸造为FirebaseUser其固定的错误,并且应用程序已成功建立,但是当我点击登录或创建帐户,调试控制台表示错误类型“ AuthResult”不是强制类型转换中“ FirebaseUser”类型的子类型
firebase_auth 0.12.0更新之前的主要登录和创建帐户功能代码
Future<String> signIn(String email, String password) async {
FirebaseUser user = await
FirebaseAuth.instance.signInWithEmailAndPassword(
email: email, password: password);
return user.uid;
}
Future<String> createUser(String email, String password) async {
FirebaseUser user = await
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: email, password: password);
return user.uid;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,在更新(firebase_auth 0.12.0)之后,相同的代码开始引发此错误,
A value of type 'AuthResult' can't be assigned to a variable of type
'FirebaseUser'.
Try changing the type of the variable, or casting the right-hand …Run Code Online (Sandbox Code Playgroud)