【发布时间】:2021-07-18 06:11:18
【问题描述】:
我有一个带有导航抽屉的颤振应用程序。它具有三个重定向到相应屏幕的路由。但是,当我单击当前所在的特定屏幕时,会重复创建该屏幕的新实例。我不希望一次又一次地创建当前选定页面的实例。以 Gmail 的抽屉式导航为例。当我单击所选页面时,它不会创建新实例。我想拥有那个功能。谁能帮我解决这个问题?
class NavList extends StatefulWidget {
@override
_NavListState createState() => _NavListState();
}
class _NavListState extends State<NavList> {
@override
Widget build(BuildContext context) {
return Drawer(
child: Container(
width: MediaQuery.of(context).size.width * 0.70, //70% of the screen
child: Column(
// padding: EdgeInsets.zero,
children: <Widget>[
Expanded(
child: Column(
children: [
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'),
),
),
ListTile(
hoverColor: Colors.deepOrange.shade300,
title: Text('Sellers'),
leading: IconButton(
icon: Icon(Icons.people),
onPressed: () async {
Navigator.pop(context);
Navigator.pushNamed(context, SellerScreen.id);
},
),
onTap: () async {
Navigator.pop(context);
Navigator.pushNamed(context, SellerScreen.id);
},
),
ListTile(
hoverColor: Colors.deepOrange.shade300,
title: Text('Shops'),
leading: IconButton(
icon: Icon(Icons.shop),
onPressed: () async {
Navigator.pop(context);
Navigator.pushNamed(context, ShopScreen.id);
},
),
onTap: () {
Navigator.pop(context);
Navigator.pushNamed(context, ShopScreen.id);
},
),
ListTile(
hoverColor: Colors.deepOrange.shade300,
title: Text('Orders'),
leading: IconButton(
icon: Icon(Icons.monetization_on),
onPressed: () async {
Navigator.pop(context);
Navigator.pushNamed(context, OrderScreen.id);
},
),
onTap: () async {
Navigator.pop(context);
Navigator.pushNamed(context, OrderScreen.id);
},
),
ListTile(
hoverColor: Colors.deepOrange.shade300,
title: Text('Logout'),
leading: IconButton(
icon: Icon(Icons.logout),
onPressed: () async {
Navigator.pop(context);
Navigator.pushNamed(context, LoginScreen.id);
},
),
onTap: () async {
Navigator.pop(context);
Navigator.pushNamed(context, LoginScreen.id);
},
),
],
),
),
Container(
child: Padding(
padding: EdgeInsets.only(bottom: 5.0),
child: Text(
'Version 1.0.1',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
)
],
),
),
);
}
}
【问题讨论】:
标签: flutter stack flutter-layout state dart-pub