Skip to content

Commit 7a25a4f

Browse files
committed
feat:AlertDialog
1 parent 8ea1e72 commit 7a25a4f

File tree

5 files changed

+127
-0
lines changed

5 files changed

+127
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## **AlertDialog**
2+
3+
>
4+
AlertDialog向用户传递信息的弹出框,警报对话框
5+
* 一般使用在通知用户需要确认的情况,具有可选标题和可选的操作列表
6+
* 对于为用户提供多个选项之间选择的对话框,请考虑使用SimpleDialog
7+
* 如果内容太大无法放入屏幕,请优先考虑使用SingleChildScrollView来避免内容溢出
8+
* 需要注意,AlertDialog使用child大小来调节自身大小,使用如ListView,GridView和CustomScrollView将无法工作
9+
10+
### 构造方法
11+
``` dart
12+
AlertDialog({
13+
Key key,
14+
this.title,
15+
this.titlePadding,
16+
this.content,
17+
this.contentPadding = const EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
18+
this.actions,
19+
this.semanticLabel,
20+
this.shape,
21+
})
22+
```
23+
24+
### 属性介绍
25+
* title: 对话框的标题(可选)
26+
* titlePadding: 标题的周围填充
27+
* content: 对话框的(可选)内容以较浅的字体显示在对话框的中央
28+
* contentPadding: 内容的周围填充
29+
* action: 显示在对话框底部的可选操作集
30+
* semanticLabel: 可访问性框架用于在打开和关闭对话框时通知屏幕转换的对话框的语义标签
31+
* shape: 对话框边框的形状
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Index extends StatefulWidget {
4+
@override
5+
_IndexState createState() => _IndexState();
6+
}
7+
8+
class _IndexState extends State<Index> {
9+
10+
List Action = ['Ok', 'Cancel'];
11+
String _choice = 'Nothing';
12+
13+
Future _openAlertDialog () async {
14+
final action = await showDialog(
15+
context: context,
16+
barrierDismissible: false, // user must tap button
17+
builder: (BuildContext context) {
18+
return AlertDialog(
19+
title: Text('AlertDialog'),
20+
content: Text('Are you sure about this?'),
21+
titlePadding: EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 0.0),
22+
contentPadding: EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
23+
actions: List.generate(2, (index) {
24+
return FlatButton(
25+
child: Text('${Action[index]}',style: TextStyle(color: Theme.of(context).primaryColor),),
26+
onPressed: (){
27+
Navigator.pop(context, Action[index]);
28+
},
29+
);
30+
}),
31+
);
32+
}
33+
);
34+
switch (action) {
35+
case 'Ok':
36+
setState(() {
37+
_choice = 'Ok';
38+
});
39+
break;
40+
case 'Cancel':
41+
setState(() {
42+
_choice = 'Cancel';
43+
});
44+
break;
45+
default:
46+
}
47+
}
48+
49+
50+
@override
51+
Widget build(BuildContext context) {
52+
return Scaffold(
53+
appBar: AppBar(title: Text('AlertDialog'),),
54+
body: Center(
55+
child: Text('你的选择是:$_choice'),
56+
),
57+
floatingActionButton: FloatingActionButton(
58+
onPressed: _openAlertDialog,
59+
child: Icon(Icons.camera_enhance, color: Colors.white, size: 30.0,),
60+
backgroundColor: Theme.of(context).primaryColor,
61+
),
62+
);
63+
}
64+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3+
import 'demo.dart' as Demo;
4+
5+
class Index extends StatefulWidget {
6+
static String title = 'AlertDialog';
7+
static String originCodeUrl = '';
8+
static String mdUrl = 'docs/widget/bulletbox/alertdialog/index.md';
9+
@override
10+
_IndexState createState() => _IndexState();
11+
}
12+
13+
class _IndexState extends State<Index> {
14+
@override
15+
Widget build(BuildContext context) {
16+
return WidgetComp.Index(
17+
title: Index.title,
18+
originCodeUrl: Index.originCodeUrl,
19+
mdUrl: Index.mdUrl,
20+
demoChild: <Widget>[
21+
Demo.Index()
22+
],
23+
);
24+
}
25+
}

lib/widget/bulletbox/index.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:efox_flutter/store/objects/widget_info.dart';
22
import 'simpledialog/index.dart' as SimpleDialog;
3+
import 'alertdialog/index.dart' as AlertDialog;
34

45
const nameSpaces = '/bulletbox_';
56

@@ -8,6 +9,11 @@ List widgets = [
89
widget: SimpleDialog.Index(),
910
code: 57451, // branding_watermark
1011
title: SimpleDialog.Index.title
12+
),
13+
ItemInfo(
14+
widget: AlertDialog.Index(),
15+
code: 59644, // camera_enhance
16+
title: AlertDialog.Index.title
1117
)
1218
];
1319

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ flutter:
7979
- docs/widget/regular/listbody/
8080
- docs/widget/regular/layoutbuilder/
8181
- docs/widget/bulletbox/simpledialog/
82+
- docs/widget/bulletbox/alertdialog/
8283
- docs/widget/navigator/appbar/
8384
- docs/widget/navigator/scaffold/
8485
# An image asset can refer to one or more resolution-specific "variants", see

0 commit comments

Comments
 (0)