-
Flutter Dialog
(1)AboutDialog

(2)AlertDialog

(3)SimpleDialog

// AboutDialog
void showAboutDialog(BuildContext context) {
showDialog(context: context, builder: (_) => new AboutDialog(
applicationName: 'AndroidStudio',
applicationIcon: Icon(Icons.add_chart),
children: [
Text('这是一个AndroidStudio')
],
));
}
// SimpleDialog
void showSimpleDialog(BuildContext context) {
showDialog(context: context, builder: (_) => new SimpleDialog(
title: Text('选择'),
children: [
SimpleDialogOption(
child: Text('选项1'),
onPressed: () {
Navigator.of(context).pop();
},
),
SimpleDialogOption(
child: Text('选项2'),
onPressed: () {
Navigator.of(context).pop();
},
),
SimpleDialogOption(
child: Text('选项3'),
onPressed: () {
Navigator.of(context).pop();
},
),
SimpleDialogOption(
child: Text('选项4'),
onPressed: () {
Navigator.of(context).pop();
},
)
],
));
}
// AlertDialog
void showAlertDialog(BuildContext context) {
showDialog(context: context, builder: (_) => new AlertDialog(
title: Text('标题'),
content: SingleChildScrollView(
child: ListBody(
children: [
Text('较长的List。。。'),
Text('较长的List。。。'),
Text('较长的List。。。'),
Text('较长的List。。。'),
Text('较长的List。。。'),
Text('较长的List。。。'),
Text('较长的List。。。'),
Text('较长的List。。。'),
Text('较长的List。。。'),
],
),
),
actions: [
FlatButton(onPressed: () {
Navigator.of(context).pop();
}, child: Text('确定')),
FlatButton(onPressed: () {
Navigator.of(context).pop();
}, child: Text('取消')),
],
));
}
本文介绍了Flutter中三种对话框的使用方法:AboutDialog用于显示应用信息;AlertDialog用于提示重要信息或警告;SimpleDialog用于提供多个选项供用户选择。每种对话框都附带了具体的代码示例。
3645

被折叠的 条评论
为什么被折叠?



