我正在开发一个颤振项目,该项目有一个带有三个路线的导航抽屉。每当我前往特定路线并返回时,导航抽屉就会自动打开。我希望导航抽屉保持关闭状态,除非用户特别点击它。有什么办法可以做到这一点?
这是我的代码:
class NavList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
UserAccountsDrawerHeader(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/orange.png'),
fit: BoxFit.cover,
)),
arrowColor: Colors.deepOrangeAccent[700],
accountName: Text(''),
accountEmail: Text(
'username@gmail.com',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
currentAccountPicture: CircleAvatar(
radius: 22.0,
backgroundColor: Colors.deepOrangeAccent[700],
backgroundImage: AssetImage('images/profile.png'),
),
),
ListItems(
listTitle: 'Shops',
listIcon: Icon(Icons.shop),
listFunction: () {
Navigator.pushNamed(context, ShopScreen.id);
},
),
ListItems(
listTitle: 'Orders',
listIcon: Icon(Icons.monetization_on),
listFunction: () {
Navigator.pushNamed(context, OrderScreen.id);
},
),
ListItems(
listTitle: 'Logout',
listIcon: Icon(Icons.logout),
listFunction: () {
Navigator.pushNamed(context, LoginScreen.id);
},
),
],
),
);
}
}
I have refactored ListItems.
class ListItems extends StatelessWidget {
ListItems({this.listTitle, this.listIcon, this.listFunction});
final String listTitle;
final Icon listIcon;
final Function listFunction;
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(listTitle),
leading: IconButton(
icon: listIcon,
onPressed: () {
},
),
onTap: listFunction,
);
}
}