The Dialog widget in Flutter pops up on the screen to get confirmation regarding the critical/irreversible task or let users know about the crucial information about the app. The dialog widget quickly draws the user’s attention by appearing in the center of the screen. When it appears it may or may not allow users to interact with other UI elements of your app and can be dismissed by clicking outside of a dialog. So in this tutorial, we’ll see how you can show 2 types of Flutter Dialog that include AlertDialog and SimpleDialog with practical examples.
https://codeprozone.com/code/dart/147803/flutter-close-dialog.html
flutter close dialog
- Kód: Vybrat vše
showDialog(
context: context,
builder: (_) {
return AlertDialog(
title: Text('Wanna Exit?'),
actions: [
FlatButton(
onPressed: () => Navigator.pop(context, false), // passing false
child: Text('No'),
),
FlatButton(
onPressed: () => Navigator.pop(context, true), // passing true
child: Text('Yes'),
),
],
);
}).then((exit) {
if (exit == null) return;
if (exit) {
// user pressed Yes button
} else {
// user pressed No button
}
});
show dialog close flutter
- Kód: Vybrat vše
BuildContext dialogContext; // <<----
showDialog(
context: context, // <<----
barrierDismissible: false,
builder: (BuildContext context) {
dialogContext = context;
return Dialog(
child: new Row(
mainAxisSize: MainAxisSize.min,
children: [
new CircularProgressIndicator(),
new Text("Loading"),
],
),
);
},
);
await _longOperation();
Navigator.pop(dialogContext); // <<----