Flutter Drawer:抽屉的打开与关闭
创建抽屉的时候,导航会自动的添加按钮,左抽屉的话,导航左边会自动添加按钮,右边也是同样的道理。
但是,如果你已经在导航上面已经设置了按钮,将不会捆绑效果。
正常的话,点击对应的按钮可以弹出抽屉。
不止手势哦~
关闭可以通过下面的代码:
Navigator.pop(context)
代码:
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
backgroundColor: Colors.grey[100],
appBar: AppBar(
title: Text('Muzico'),
elevation: 0.0,
bottom: TabBar(
unselectedLabelColor: Colors.black38,
indicatorColor: Colors.green,
indicatorSize: TabBarIndicatorSize.label,
indicatorWeight: 5.0,
tabs: <Widget>[
Tab(icon: Icon(Icons.local_bar),),
Tab(icon: Icon(Icons.local_cafe),),
Tab(icon: Icon(Icons.local_offer),),
],
),
),
body: TabBarView(
children: <Widget>[
Icon(Icons.local_bar, size: 128.0, color: Colors.black12,),
Icon(Icons.local_cafe, size: 128.0, color: Colors.black12,),
Icon(Icons.local_offer, size: 128.0, color: Colors.black12,),
],
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('header'.toUpperCase()),
decoration: BoxDecoration(
color: Colors.grey[300],
),
),
ListTile(
title: Text('AAAAAA', textAlign: TextAlign.right,),
trailing: Icon(Icons.message, color:Colors.black12, size: 25.0,),
onTap: () => Navigator.pop(context),
),
ListTile(
title: Text('AAAAAA', textAlign: TextAlign.left,),
leading: Icon(Icons.message, color:Colors.black12, size: 25.0,),
onTap: () => Navigator.pop(context),
),
],
),
),
),
);
}
}
点击对应的内容,就会关闭抽屉。