【问题标题】:Navigator.pushedName does not work. flutterNavigator.pushedName 不起作用。扑
【发布时间】: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


【解决方案1】:

由于 DoctorAccountSetup.Id 是您页面的名称,请尝试将其更改为 main.dart 中的字符串以进行测试,即: 使路由名称如下所示:

'/doctorAccountSetup': (context) => DoctorAccountSetup(),

并将其用于导航。

if (user!=null){    
Navigator.pushNamed(context, "/doctorAccountSetup");
}

会发生什么?

【讨论】:

  • DoctorAccountSetup.id = String routeName.
  • 我修改了我的答案,尝试一下,请更新发生了什么。
  • 我尝试使用字符串,没有发生相同的状态。
  • 调试控制台发生了什么,输出是什么?此外,删除您的 auth 函数周围的括号。 user = await _auth.createUserWithEmailAndPassword(email: _emailController.text,password:_passwordController.text);
  • I/flutter (19999): mail@gmail.com I/flutter (19999): 12345As! I/flutter (19999):验证 OK!提交! W/System (19999):忽略标头 X-Firebase-Locale,因为它的值为 null。 2 I/System.out(19999): (HTTPLog)-Static: isSBSettingEnabled false I/flutter (19999): mail@gmail.com I/flutter (19999): 12345As!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-18
  • 2022-01-21
  • 2021-11-04
  • 2023-01-31
  • 1970-01-01
  • 1970-01-01
  • 2022-11-20
相关资源
最近更新 更多