AlertDialog
void _showAlertDialog() {
showDialog<int>(
context: context,
//对话框以外是否可以点击消失弹框
barrierDismissible: true,
builder: (BuildContext context) {
return new AlertDialog(
title: new Text('弹框标题'),
//可滑动
content: new Text('弹框内容'),
actions: <Widget>[
new FlatButton(
child: new Text('取消'),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text('确定'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
});
}
SimpleDialog
void _showSimpleDialog() {
showDialog<Null>(
context: context,
builder: (BuildContext context) {
return new SimpleDialog(
title: new Text('选择性别'),
children: <Widget>[
new SimpleDialogOption(
child: new Text('男'),
onPressed: () {
Navigator.of(context).pop();
},
),
new SimpleDialogOption(
child: new Text('女'),
onPressed: () {
Navigator.of(context).pop();
},
),
new SimpleDialogOption(
child: new Text('保密'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
CupertinoAlertDialog
void _showIOSDialog(BuildContext cxt) {
showCupertinoDialog<int>(
context: cxt,
builder: (cxt) {
return new CupertinoAlertDialog(
title: Text('提示'),
content: Text('是否退出应用'),
actions: <Widget>[
new Container(
decoration: BoxDecoration(
border: Border(
right: BorderSide(color: Color(0xFFD9D9D9), width: 0.5),
top: BorderSide(color: Color(0xFFD9D9D9), width: 0.5))),
child: CupertinoDialogAction(
child: new Text("确定"),
onPressed: () {
Navigator.pop(context);
},
),
),
new Container(
decoration: BoxDecoration(
border: Border(
top: BorderSide(color: Color(0xFFD9D9D9), width: 0.5))),
child: CupertinoDialogAction(
child: new Text("取消"),
onPressed: () {
Navigator.pop(context);
},
),
)
],
);
});
}