Skip to content

Commit 5ffdc87

Browse files
committed
Merge branch 'ysz' into test
2 parents 57db272 + 5fa4af6 commit 5ffdc87

File tree

6 files changed

+117
-4
lines changed

6 files changed

+117
-4
lines changed

assets/imgs/avatar.png

251 KB
Loading

assets/nothing.png

-8.51 KB
Binary file not shown.

docs/widget/navigator/drawer/index.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,50 @@
1-
## **文档完善中**
1+
## **Drawer**
2+
> 抽屉式组件,从Scaffold边缘水平滑出左侧菜单,也可通过Scaffold.of(context).openDrawer()显示左侧菜单。关闭页面通过Navigator.pop(context)。
3+
4+
### 构造函数
5+
```
6+
Drawer({
7+
Key key,
8+
double elevation: 16.0,
9+
Widget child,
10+
String semanticLabel
11+
})
12+
```
13+
14+
### 属性介绍
15+
- child: 菜单内容
16+
- elevation:导航栏底部阴影
17+
18+
### 高级用法
19+
- 关闭菜单
20+
> Navigator.pop(context)
21+
- 打开菜单
22+
> 方法一: Scaffold.of(context).openDrawer()
23+
```
24+
使用context变量时,需要注意在scaffold中增加Builder来获取到context,该context才是scaffold中的上下文对象,而Build build(BuildContext context)是外层类的上下文,没法操作菜单
25+
Builder(
26+
builder: (context) {
27+
return RaisedButton(
28+
onPressed: () {
29+
Scaffold.of(context).openDrawer();
30+
},
31+
child: Text("点击滑出左侧菜单"),
32+
);
33+
},
34+
),
35+
```
36+
37+
> 方法二: static GlobalKey<ScaffoldState> _globalKey= new GlobalKey();
38+
```
39+
定义globalKey
40+
41+
static GlobalKey<ScaffoldState> _globalKey= new GlobalKey();
42+
...
43+
Scaffold(
44+
key: _globalKey , //设置key
45+
...
46+
)
47+
48+
通过globalkey操作菜单状态
49+
_globalKey.currentState.openDrawer()
50+
```

lib/components/exampleComp.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class Index extends StatelessWidget {
1212
@override
1313
Widget build(BuildContext context) {
1414
Size size = MediaQuery.of(context).size;
15-
double _dp = 1.4;
15+
double _dp = 1.5;
1616
return Store.connect(
1717
builder: (context, child, MainStateModel model) {
1818
return Center(
1919
child: Container(
20-
width: size.width / _dp,
20+
width: size.width,
2121
height: size.height / _dp,
2222
margin: EdgeInsets.all(30 / _dp),
2323
decoration: BoxDecoration(

lib/widget/navigator/drawer/demo.dart

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,70 @@ class _IndexState extends State<Index> {
1818
title: Text('Drawer'),
1919
),
2020
body: Center(
21-
child: Text('更新中'),
21+
child: Column(
22+
mainAxisAlignment: MainAxisAlignment.center,
23+
children: [
24+
Builder(
25+
builder: (context) {
26+
return RaisedButton(
27+
onPressed: () {
28+
Scaffold.of(context).openDrawer();
29+
},
30+
child: Text("点击滑出左侧菜单"),
31+
);
32+
},
33+
),
34+
Text('从左侧中滑出菜单组件'),
35+
],
36+
),
37+
),
38+
drawer: Drawer(
39+
child: Column(
40+
crossAxisAlignment: CrossAxisAlignment.start,
41+
children: <Widget>[
42+
Padding(
43+
padding: const EdgeInsets.only(top: 38.0),
44+
child: Row(
45+
children: <Widget>[
46+
Padding(
47+
padding: const EdgeInsets.symmetric(horizontal: 16.0),
48+
child: ClipOval(
49+
child: Image.asset(
50+
"assets/imgs/avatar.png",
51+
width: 80,
52+
),
53+
),
54+
),
55+
Text(
56+
"Guest",
57+
style: TextStyle(fontWeight: FontWeight.bold),
58+
)
59+
],
60+
),
61+
),
62+
Expanded(
63+
child: ListView(
64+
children: <Widget>[
65+
ListTile(
66+
leading: Icon(Icons.account_circle),
67+
title: Text('Change Account'),
68+
),
69+
ListTile(
70+
leading: Icon(Icons.settings),
71+
title: Text('Setting'),
72+
),
73+
ListTile(
74+
leading: Icon(Icons.close),
75+
title: Text('点击关闭菜单'),
76+
onTap: () {
77+
Navigator.pop(context);
78+
},
79+
),
80+
],
81+
),
82+
),
83+
],
84+
),
2285
),
2386
);
2487
}

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ flutter:
5858
assets:
5959
- locale/
6060
- assets/
61+
- assets/imgs/
6162
- docs/widget/scrollview/customscrollview/
6263
- docs/widget/scrollview/gridview/
6364
- docs/widget/scrollview/listview/

0 commit comments

Comments
 (0)