【问题标题】:How can i add circular progress indicator on "onPressed" in the follwing code?如何在以下代码中的“onPressed”上添加循环进度指示器?
【发布时间】:2022-01-14 14:09:08
【问题描述】:
child: RaisedButton(
                    color: AppColors.darkGreenColor,
                    onPressed: () async{
                      passwordController.text == '' ||concatePhoneNumber == '' ? Get.snackbar("Please Enter Mobile or Password", '',colorText: Colors.white,backgroundColor: AppColors.darkGreenColor):
                      loginUser();
                    },
                    child: Text(AppString.login,
                      style:AppTextStyles.appTextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white
                     )
                    ),
                  ),

以下是 loginUser() 函数的代码

loginUser() {
final form = _formKey.currentState;

if (form!.validate()) {

  form.save();
  var jsonData = {
    "phone_number": concatePhoneNumber,
    "password": passwordController.text,
  };
  loginController.loginUser(jsonData);
}

}

我想在整个屏幕上显示圆形进度条,直到按下登录按钮时加载数据

【问题讨论】:

  • 我想不是问题。它只是告诉我们您希望我们为您完成繁重的工作。你被困在哪里了?你研究了什么?你试过什么?需要明确的是,我们会在 stackoverflow 上为您提供帮助,但我们不是免费的“我的想法”服务,请参阅 how to askMinimal, Complete and Verifiable Example
  • @RiggsFolly 我正在尝试添加“if”条件,其中条件检查是否未加载数据但显示循环进度指示器,否则执行它的“form.validate”部分。我是新来的,所以请在代码中帮助我。

标签: flutter async-await future dart-null-safety


【解决方案1】:
Here is a solution, use setState to implement circular progress bar


bool isloading=false;
child: !isloading ? RaisedButton(
                    color: AppColors.darkGreenColor,
                    onPressed: () async{
                     
                      if(passwordController.text == '' ||phoneNumber.text == '')
                      {Get.snackbar("Please Enter Mobile or Password", '',colorText: Colors.white,backgroundColor: AppColors.darkGreenColor);
                      
                      }
                      if(_formKey.currentState!.validate() && passwordController.text!=''){
                      _formKey.currentState!.save();
                      
                        
                        
                           setState(() {
                        
                        isloading=true;
                        
                      });
                      
                      
                      await loginUser();
                       
                      
                
                      setState(() {
                        
                        isloading=false;
                        isloading=!isloading;
                      });
                      

                      
                      }
                    },
                    child: Text(AppString.login,
                      style:AppTextStyles.appTextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white
                     )
                    ),
                  ): Center(child: CircularProgressIndicator())
                ),

【讨论】:

    猜你喜欢
    • 2020-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2011-02-21
    • 1970-01-01
    相关资源
    最近更新 更多