Drawer侧边栏抽屉

Posted by アライさん on 2019年11月26日

打开侧边栏抽屉:

1
2
3
4
5
6
7
8
9
10
11
class _HomePageState extends State<HomePage> {
GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
);
}
}
// _scaffoldKey.currentState.openDrawer();

CustomDrawer:

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
import 'package:flutter/material.dart';
import 'package:fress/add_rss_url.dart';

class CustomDrawer extends StatelessWidget {

final TextStyle itemTextStyle = TextStyle(
color: Colors.black87,
fontSize: 16.0,
);

@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text(
'侧栏 Header',
style: TextStyle(color: Colors.white, fontSize: 18.0),
),
decoration: BoxDecoration(color: Theme.of(context).primaryColor),
),
ListTile(
leading: Icon(
Icons.add,
size: 20.0,
color: Theme.of(context).primaryColor,
),
title: Text(
'添加新的rss源',
style: itemTextStyle,
),
onTap: () {
//添加rss
Navigator.pop(context);
Navigator.push(context, MaterialPageRoute(
builder: (context) => AddRssUrlPage()
));
},
),
ListTile(
leading: Icon(
Icons.remove_circle,
size: 20.0,
color: Theme.of(context).primaryColor,
),
title: Text(
'删除现有rss源',
style: itemTextStyle,
textAlign: TextAlign.left,
),
onTap: () {
//删除rss
// Navigator.pop(context);
},
),
ListTile(
leading: Icon(
Icons.delete,
size: 20.0,
color: Theme.of(context).primaryColor,
),
title: Text(
'清除缓存',
style: itemTextStyle,
textAlign: TextAlign.left,
),
onTap: () {
//删除rss
Navigator.pop(context);
},
),
],
),
);
}

}