flutter pop-up dialog box, flutter prompt box
For more articles, please see Lutter from entry to mastery
# flutter dialog
Here is a brief description of the three pop-up methods of flutter dialog
- AlertDialog
- SimpleDialog
- CupertionDialogAction
1 AlertDialog
void showAlertDialog() {
showDialog<Null>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return new AlertDialog(
title: new Text('标题'),
//可滑动
content: new SingleChildScrollView(
child: new ListBody (
children : < Widget > [
new Text ( 'Content 1' ) ,
new Text ( ' Content 2' ) ,
new Text ( ' Content 1' ) ,
new Text ( ' Content 2' ) ,
] ,
) ,
) ,
actions : < Widget > [
new FlatButton (
child : new Text('确定'),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text('取消'),
onPressed: () {
Navigator.of(context).pop() ;
} ,
) ,
] ,
) ;
} ) ;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
2 SimpleDialog
void showSimpleDialog() {
showDialog<Null>(
context: context,
builder: (BuildContext context) {
return new SimpleDialog(
title: new Text('选择'),
children: <Widget>[
new SimpleDialogOption(
child: new Text('选项 1'),
onPressed: () {
Navigator.of(context).pop();
},
),
new SimpleDialogOption(
child: new Text('选项 2'),
onPressed: () {
Navigator.of(context).pop();
} ,
) ,
] ,
) ;
} ,
) ;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
3 CupertionDialogAction ios style
void showCupertinoAlertDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text("This is an iOS style dialog"),
content: Column(
children: <Widget>[
SizedBox(
height: 10,
),
Align(
child: Text("This is the message"),
alignment: Alignment(0, 0),
),
],
),
actions: <Widget>[
CupertinoDialogAction(
child: Text("Cancel"),
onPressed: () {
Navigator.pop(context);
print("Cancel");
},
),
CupertinoDialogAction(
child: Text("OK"),
onPressed: () {
print("OK");
},
),
],
);
});
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35