【发布时间】:2021-03-23 12:58:56
【问题描述】:
我目前正在 VScode 上开发一个应用程序。在我的注册页面中,我使用 createUserWithEmailAndPassword(firebase 身份验证),一旦单击注册按钮,电子邮件就会显示在 Firebase 身份验证中,但它不会导航到用户可以输入其个人资料信息的下一页。如果我热重启或热重新加载项目,应用程序会冻结,我必须终止它才能再次工作。
SignupButton(
text: 'Sign Up',
color: kColor,
onTap: () async {
if (_formKey.currentState.validate()) {
try {
final user = (await _auth
.createUserWithEmailAndPassword(
email: _emailController.text,
password:
_passwordController.text))
;
if (user!=null){Navigator.pushNamed(
context, DoctorAccountSetup.id);}
} catch (e) {
print('Error Happened!!!: $e');
}
}
}),
main.dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: Registration.id,
routes: {
// id = Static String id = 'InitialPage'; for each dart file
InitialPage.id: (context) => InitialPage(),
Login.id: (context) => Login(),
Infopage.id: (context) => Infopage(),
Registration.id: (context) => Registration(),
DoctorAccountSetup.id: (context) => DoctorAccountSetup(),
},
);
}
}
我该如何解决这个问题?
编辑
SignupButton(
text: 'Sign Up',
color: kColor,
onTap: () {
Navigator.pushNamed(context, "/doctorAccountSetup");
// if (_formKey.currentState.validate()) {}
// when the if statement is commented the navigation works fine.
// Might the problem be in the try and catch?
}),
【问题讨论】:
-
请在
MaterialApp(..., routes: ...)中提供routes的值。另外,“DoctorAccountSetup.id”的值是多少?
标签: flutter dart firebase-authentication