【问题标题】:Flutter print() and delayed function not runningFlutter print() 和延迟函数未运行
【发布时间】:2020-04-20 23:54:45
【问题描述】:

我正在尝试延迟导航到另一个屏幕,但延迟功能不起作用,控制台中也没有显示打印语句。最近我升级了flutter。不知道是不是这个原因。即使调试也无法正常工作。有时来回延迟会起作用。有时不会。

Padding(
      padding: EdgeInsets.only(bottom: containerHeight * 0.08, top: 10),
      child: _isLoading ? CircularProgressIndicator() : RaisedButton(
      color: Colors.red,
              onPressed: ()
                async {
                 if(_formkey.currentState.validate())
                  {
                   print('Login Form Vaildated');
                   setState(() {
                   _isLoading = true;
                   });

                   try {
                     print('Going to login');
                      await Utils.login(usernameController.text, passController.text);
                      Future.delayed(const Duration(seconds: 7)).then((_){
                      print('Inside Delayed');
                      Navigator.of(context)
                      .pushReplacement(MaterialPageRoute(builder: (_) {
                                                          return DataEntryScreen(userName:Utils.email,);
                                                        }));

                       setState(() {
                       _isLoading = false;
                       });
                      });
                      } on HttpException catch(error){
                            print('Inside HTTP Exp');
                            var errorMessage = 'Authentication failed';
                            if (error.toString().contains('EMAIL_EXISTS')) {
                              errorMessage = 'This email address is already in use.';
                             } else if (error.toString().contains('INVALID_EMAIL')) {
                               errorMessage = 'This is not a valid email address';
                             } else if (error.toString().contains('WEAK_PASSWORD')) {
                               errorMessage = 'This password is too weak.';
                             } else if (error.toString().contains('EMAIL_NOT_FOUND')) {
                               errorMessage = 'Could not find a user with that email.';
                             } else if (error.toString().contains('INVALID_PASSWORD')) {
                               errorMessage = 'Invalid password.';
                             }
                             setState(() {
                              _isLoading = false;
                             });
                              _showErrorDialog(errorMessage);
                              print(errorMessage);
                              } catch(error){
                                 const errorMessage ='Could not authenticate you. Please try again later.';
                                 _showErrorDialog(errorMessage);
                                  setState(() {
                                       _isLoading = false;
                                      });

                                       }
                                     }
                                 },
                                  child: Text(
                                    'Sign in',
                                    style: TextStyle(color: Colors.white),
                                  ),
                                ),
                              )

【问题讨论】:

  • 请分享flutter医生的结果

标签: flutter dart


【解决方案1】:

解决了这个问题。 Android Studio 没有应用我所做和保存的更改。 所以这就是我所做的。

  • 升级了 pub 包,因为我之前升级过 flutter 并没有 升级软件包。
  • 创建了一个新项目并复制了 lib 中的所有 dart 文件 旧项目到新项目。
  • 还安装了新的仿真器设备,以防旧数据中的一些旧数据 模拟器导致了这个问题。

现在一切正常。

【讨论】:

    猜你喜欢
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 2014-09-15
    • 2019-11-01
    • 2013-06-19
    • 1970-01-01
    相关资源
    最近更新 更多