Flutter modal dialog code example
Example 1: show dialog close flutter
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); // <<----
Example 2: showdialog with builder flutter
showDialog(
context: context,
builder: (BuildContext context) => new AlertDialog(
title: new Text('Warning'),
content: new Text('Hi this is Flutter Alert Dialog'),
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.close),
onPressed: () {
Navigator.pop(context);
})
],
));
Example 3: flutter modal dialog fullscreen
showDialog( context: context, builder: (BuildContext context) { return Dialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20.0)), //this right here child: Container( height: 200, child: Padding( padding: const EdgeInsets.all(12.0), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ TextField( decoration: InputDecoration( border: InputBorder.none, hintText: 'What do you want to remember?'), ), SizedBox( width: 320.0, child: RaisedButton( onPressed: () {}, child: Text( "Save", style: TextStyle(color: Colors.white), ), color: const Color(0xFF1BC0C5), ), ) ], ), ), ), ); });
Example 4: flutter modal dialog fullscreen
showGeneralDialog( context: context, barrierDismissible: true, barrierLabel: MaterialLocalizations.of(context) .modalBarrierDismissLabel, barrierColor: Colors.black45, transitionDuration: const Duration(milliseconds: 200), pageBuilder: (BuildContext buildContext, Animation animation, Animation secondaryAnimation) { return Center( child: Container( width: MediaQuery.of(context).size.width - 10, height: MediaQuery.of(context).size.height - 80, padding: EdgeInsets.all(20), color: Colors.white, child: Column( children: [ RaisedButton( onPressed: () { Navigator.of(context).pop(); }, child: Text( "Save", style: TextStyle(color: Colors.white), ), color: const Color(0xFF1BC0C5), ) ], ), ), ); });