Ad
How Can I Add Circular Progress Indicator On "onPressed" In The Follwing Code?
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
)
),
),
Following is the code for loginUser() function
loginUser() {
final form = _formKey.currentState;
if (form!.validate()) {
form.save();
var jsonData = {
"phone_number": concatePhoneNumber,
"password": passwordController.text,
};
loginController.loginUser(jsonData);
}
}
I want to show circular progress bar on whole screen until data is loaded while pressing login button
Ad
Answer
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())
),
Ad
source: stackoverflow.com
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?
Ad