【发布时间】:2020-03-29 19:58:01
【问题描述】:
我在下面设置了转换用户代码: 当我输入电子邮件和密码并单击注册时,firebase 会进行更改,但屏幕不会转到 ProfileScreen,它只是保持加载状态。一旦我热重启应用程序,它就会显示正确的页面。
//create User object based on firebase user
User _userFromFirebaseUser(FirebaseUser user){
return user != null ? User(uid: user.uid, email: user.email) : null;
}
//convert users from anonymous
Future convertUserWIthEmail(String email, String password) async {
final currentUser = await _auth.currentUser();
final credential = EmailAuthProvider.getCredential(email: email, password: password);
await currentUser.linkWithCredential(credential);
return _userFromFirebaseUser(currentUser);
}
个人资料屏幕包装器
class ProfileWrapper extends StatelessWidget {
static const String id = 'profile_wrapper';
@override
Widget build(BuildContext context) {
final user = Provider.of<User>(context);
if (user.email != null){
return ProfileScreen();
} else {
return ProfileRegister();
}
}
}
PROFILE_REGISTER 页面中的实现 - RoundedButton 是一个自定义类
RoundedButton(
title: 'Register',
colour: Colors.white,
textColour: kMainColour,
onPressed: () async {
if (_formKey.currentState.validate()) {
setState(() {
loading = true;
});
dynamic result = await _authNew
.convertUserWIthEmail(
email, password);
if (result == null) {
setState(() {
loading = false;
error =
'Please enter a valid email and password';
print('ERROR HAPPENED');
});
_scaffoldKey.currentState.showSnackBar(
SnackBar(
backgroundColor: Colors.red,
content: new Text(error,
style: kErrorMessageTextStyle,
textAlign: TextAlign.center,),
duration: new Duration(seconds: 3),
)
);
}
// setState(() {
// showSpinner = true;
// });
}
}),
【问题讨论】:
标签: firebase flutter dart firebase-authentication flutter-layout