Flutter提供了很多的Dialog样式,有Android和iOS的.满足日程的大多数开发需求.

Dialog
Dialog
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

class DialogWidget extends StatefulWidget {
@override
DialogWidgetState createState() => new DialogWidgetState();
}

class DialogWidgetState extends State<DialogWidget> {
List<String> titles = [
'AlertDialog',
'AlertDialog-ListView',
'AboutDialog',
'SimpleDialog',
'CupertinoAlertDialog',
'CupertinoActionSheet',
'CupertinoPopupSurface',
];

List<String> subtitles = [
'底部的按钮最多三个',
'内容为ListView',
'含应用程序的图标,名称,版本号和版权',
'简单的对话框',
'iOS风格对话框',
'iOS风格选择框',
'iOS风格自定义内容',
];

List<bool> bools = [
false,
false,
false,
false,
false,
];

int radio = 0;

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('AlertDialog'),
),
body: ListView.builder(
itemCount: titles.length,
itemBuilder: (context, index) {
return ListTile(
dense: true,
title: Text(titles[index]),
subtitle: Text(subtitles[index]),
onTap: () {
Widget _widget;
switch (index) {
case 0:
_widget = AlertDialog(
title: Text(titles[index]),
// titlePadding: EdgeInsets.all(5.0),
content: Text('普通的AlertDialog'),
// contentPadding: EdgeInsets.all(10.0),
semanticLabel: titles[index],
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('取消')),
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('考虑一下')),
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('确认')),
],
);
_showDialog(_widget);
break;
case 1:
_widget = AlertDialog(
title: Text(titles[index]),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
_text('ListView Item 1'),
_text('ListView Item 2'),
_text('ListView Item 3'),
_text('ListView Item 4'),
_text('ListView Item 5'),
_text('ListView Item 6'),
_text('ListView Item 7'),
_text('ListView Item 8'),
_text('ListView Item 9'),
_text('ListView Item 10'),
_text('ListView Item 11'),
_text('ListView Item 12'),
],
),
),
);
_showDialog(_widget);
break;
case 2:
showAboutDialog(
context: context,
applicationIcon: Icon(Icons.accessibility),
applicationLegalese: 'Flutter 集合大全',
applicationName: 'Flutter List',
applicationVersion: '1.0.0');
break;
case 3:
_showDialog(
SimpleDialog(
title: Text('SimpleDialog'),
children: <Widget>[
SimpleDialogOption(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('关闭'),
),
SimpleDialogOption(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('确认'),
)
],
),
);
break;
case 4:
showCupertinoDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text('CupertinoAlertDialog'),
content: Text('iOS风格对话框'),
actions: <Widget>[
CupertinoDialogAction(
child: Text('关闭'),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoDialogAction(
child: Text('确认'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
break;
case 5:
showCupertinoModalPopup(
context: context,
builder: (context) {
return CupertinoActionSheet(
title: Text('CupertinoActionSheet'),
message: Text('iOS风格选择框'),
cancelButton: CupertinoActionSheetAction(
child: Text('我是取消按钮'),
onPressed: () {
Navigator.of(context).pop();
},
),
actions: <Widget>[
CupertinoActionSheetAction(
child: Text('选项一'),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoActionSheetAction(
child: Text('选项二'),
onPressed: () {
Navigator.of(context).pop();
},
),
CupertinoActionSheetAction(
child: Text('选项三'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
break;
case 6:
showCupertinoModalPopup(
context: context,
builder: (context) {
return CupertinoPopupSurface(
isSurfacePainted: true,
child: Container(
height: 300.0,
alignment: AlignmentDirectional.center,
child: Text(
'我是自定义内容',
style: TextStyle(
color: Colors.black,
fontSize: 16.0,
),
),
),
);
},
);
break;
}
},
);
},
),
);
}

@override
void initState() {
// TODO: implement initState
super.initState();
}

_showDialog(Widget widget) {
showDialog(
context: context,
builder: (context) {
return widget;
},
barrierDismissible: true,
);
}

_text(String text) {
return InkWell(
child: Text(text),
onTap: () {
Navigator.of(context).pop();
},
);
}
}