kf_drawer
Flutter 侧边菜单(抽屉)。

入门
将KFDrawer 组件作为 Scaffold 的 body,并使用 items 属性 (List<KFDrawerItem>)
您应该在 KFDrawerItem 上定义 onPressed
KFDrawer 属性
- controller (可选)
- header
- footer
- items (如果定义了 controller 则可选)
- 装饰
或者使用 controller 设置抽屉项目 (KFDrawerController)
在 KFDrawerItem 上定义 page 属性
KFDrawerController 属性
- initialPage
- items
抽屉页面组件应扩展 KFDrawerContent 组件
您可以使用 ClassBuilder 进行基于字符串的类初始化
示例
class MainWidget extends StatefulWidget {
@override
_MainWidgetState createState() => _MainWidgetState();
}
class _MainWidgetState extends State<MainWidget> {
KFDrawerController _drawerController;
@override
void initState() {
super.initState();
_drawerController = KFDrawerController(
initialPage: ClassBuilder.fromString('MainPage'),
items: [
KFDrawerItem.initWithPage(
text: Text('MAIN', style: TextStyle(color: Colors.white)),
icon: Icon(Icons.home, color: Colors.white),
page: MainPage(),
),
KFDrawerItem.initWithPage(
text: Text(
'CALENDAR',
style: TextStyle(color: Colors.white),
),
icon: Icon(Icons.calendar_today, color: Colors.white),
page: CalendarPage(),
),
KFDrawerItem.initWithPage(
text: Text(
'SETTINGS',
style: TextStyle(color: Colors.white),
),
icon: Icon(Icons.settings, color: Colors.white),
page: ClassBuilder.fromString('SettingsPage'),
),
],
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: KFDrawer(
controller: _drawerController,
header: Align(
alignment: Alignment.centerLeft,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16.0),
width: MediaQuery.of(context).size.width * 0.6,
child: Image.asset(
'assets/logo.png',
alignment: Alignment.centerLeft,
),
),
),
footer: KFDrawerItem(
text: Text(
'SIGN IN',
style: TextStyle(color: Colors.white),
),
icon: Icon(
Icons.input,
color: Colors.white,
),
onPressed: () {
Navigator.of(context).push(CupertinoPageRoute(
fullscreenDialog: true,
builder: (BuildContext context) {
return AuthPage();
},
));
},
),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color.fromRGBO(255, 255, 255, 1.0), Color.fromRGBO(44, 72, 171, 1.0)],
tileMode: TileMode.repeated,
),
),
),
);
}
}