Skip to content

Commit 0aa0eb2

Browse files
committed
feat:BottomSheet
1 parent 7a25a4f commit 0aa0eb2

File tree

6 files changed

+140
-1
lines changed

6 files changed

+140
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## **BottomSheet**
2+
3+
>
4+
底部菜单,通常情况下分享操作界面使用比较多
5+
* 显示BottomSheet我们可以通过调用:showBottomSheet或者showModalBottomSheet方法,showBottomSheet是从新打开了一个界面来显示,showModalBottomSheet是直接在当前界面的下面来显示
6+
* 两个方法都需要传入一个context和WidgetBuilder
7+
8+
### 构造方法
9+
``` dart
10+
showModalBottomSheet<T>({
11+
@required BuildContext context,
12+
@required WidgetBuilder builder,
13+
})
14+
showBottomSheet<T>({
15+
@required BuildContext context,
16+
@required WidgetBuilder builder,
17+
})
18+
```
19+
20+
### 属性介绍
21+
context:上下文
22+
builder: 构造器

lib/widget/bulletbox/alertdialog/index.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'demo.dart' as Demo;
44

55
class Index extends StatefulWidget {
66
static String title = 'AlertDialog';
7-
static String originCodeUrl = '';
7+
static String originCodeUrl = 'https://docs.flutter.io/flutter/material/AlertDialog-class.html';
88
static String mdUrl = 'docs/widget/bulletbox/alertdialog/index.md';
99
@override
1010
_IndexState createState() => _IndexState();
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
List showMBS = ['Option A', 'Option B', 'Option C'];
10+
String _choiceMBS = 'Nothing';
11+
List showBS = ["开始会话", "操作说明", "系统设置", "更多设置"];
12+
List icons = [Icons.chat, Icons.help, Icons.settings, Icons.more];
13+
14+
Future _openShowModalBottomSheet () async {
15+
final option = await showModalBottomSheet(
16+
context: context,
17+
builder: (BuildContext context) {
18+
return Container(
19+
height: 200.0,
20+
child: ListView(
21+
children: List.generate(3, (index) {
22+
return ListTile(
23+
title: Text(showMBS[index]),
24+
onTap: (){
25+
Navigator.pop(context, showMBS[index]);
26+
},
27+
);
28+
})
29+
),
30+
);
31+
}
32+
);
33+
// 使用switch可以按情况对后续赋值
34+
setState(() {
35+
_choiceMBS = option;
36+
});
37+
}
38+
39+
Future _openShowBottomSheet () async {
40+
final optionBs = await showBottomSheet(
41+
context: context,
42+
builder: (BuildContext context) {
43+
return new Container(
44+
height: 300.0,
45+
child: new Padding(
46+
padding: const EdgeInsets.all(10.0),
47+
child: new Column(
48+
children: List.generate(4, (index) {
49+
return ListTile(
50+
leading: new Icon(icons[index]),
51+
title: new Text(showBS[index]),
52+
onTap: () {
53+
Navigator.pop(context, showBS[index]);
54+
},
55+
);
56+
})
57+
))
58+
);
59+
}
60+
);
61+
}
62+
63+
@override
64+
Widget build(BuildContext context) {
65+
return Scaffold(
66+
appBar: AppBar(title: Text('BottomSheet'),),
67+
body: Center(
68+
child: Column(
69+
mainAxisAlignment: MainAxisAlignment.center,
70+
crossAxisAlignment: CrossAxisAlignment.center,
71+
children: <Widget>[
72+
FlatButton(
73+
onPressed: _openShowBottomSheet,
74+
child: Text('showBottomSheet', style: TextStyle(fontSize: 16.0),),
75+
),
76+
FlatButton(
77+
onPressed: _openShowModalBottomSheet,
78+
child: Text('showModalBottomSheet: $_choiceMBS', style: TextStyle(fontSize: 16.0),),
79+
)
80+
],
81+
),
82+
),
83+
);
84+
}
85+
}
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 = 'BottomSheet';
7+
static String originCodeUrl = '';
8+
static String mdUrl = 'docs/widget/bulletbox/bottomsheet/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,6 +1,7 @@
11
import 'package:efox_flutter/store/objects/widget_info.dart';
22
import 'simpledialog/index.dart' as SimpleDialog;
33
import 'alertdialog/index.dart' as AlertDialog;
4+
import 'bottomsheet/index.dart' as BottomSheet;
45

56
const nameSpaces = '/bulletbox_';
67

@@ -14,6 +15,11 @@ List widgets = [
1415
widget: AlertDialog.Index(),
1516
code: 59644, // camera_enhance
1617
title: AlertDialog.Index.title
18+
),
19+
ItemInfo(
20+
widget: BottomSheet.Index(),
21+
code: 59639, // card_membership
22+
title: BottomSheet.Index.title
1723
)
1824
];
1925

pubspec.yaml

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

0 commit comments

Comments
 (0)