I can't solve this problem. I'm trying to do this step by step. When users push the button, first they gonna see AlertDialog, then the function startFilePickerBig will run. After the user chose files and is done with the startFilePickerBig function AlertDialog must close. But when I add Navigator.pop(context) after "await startFilePickerBig()" , alertdialog not working. When I remove "Navigator.pop(context)" which I wrote under the "await startFilePickerBig()", AlarmDialog works fine. How can I fix this?
OutlinedButton(
style: ButtonStyle(side: MaterialStateProperty.all(const BorderSide(width: 1.0, color: Color(0xFFF38F1D))), shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(7))), foregroundColor: MaterialStateProperty.all(const Color(0xFFF38F1D))),
onPressed: () async {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text(''),
content: const Text('Pease wait, Images loading... '),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close')),],
);
});
await startFilePickerBig();
Navigator.pop(context);
},
child: const Text("Add Image"), )
CodePudding user response:
What I might do here is to use ProgressIndicator instead of AlertDialogBox with the help of ternary operator on the build function. However, as per your approach, this might work:
onPressed: () async {
await startFilePickerBig();
bool result= await showDialog(context:context, builder:( BuildContext context){
return AlertDialog(
title:Text("Pease wait, Images loading..."),
actions: [
TextButton(
child: Text("Picked"),
onPressed: (){
Navigator.of(context).pop(true);
},
),
TextButton(
child: Text("Not picked"),
onPressed: (){
Navigator.of(context).pop(false);
},
),
],
);
});
if(result==true){
//Do whatever you want
Fluttertoast.showToast(
msg: 'Items picked',
toastLength: Toast.LENGTH_LONG,
backgroundColor: kPrimaryColor);
removeFromList(item);
}else{
//Your code
}
}