嗨,我正在使用Drawer路由菜单。它可以正常工作2页,但是有一页给出了错误。
当我第一次按菜单时,菜单正常工作,然后当我转到另一页并返回时,出现此错误
我也尝试过在mainApp buut上使用路由进行路由,这对我来说似乎更容易
我的抽屉
class MyDrawer extends StatefulWidget {
@override
State<StatefulWidget> createState() => _MyDrawerState();
}
class _MyDrawerState extends State {
@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
children: <Widget>[
DrawerHeader(
child: Align(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Test",
style: TextStyle(color: Colors.white, fontSize: 25.0),
),
],
),
),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
leading: Icon(Icons.home),
title: Text('Main'),
trailing: Icon(Icons.arrow_right),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Main(),
));
},
),
ListTile(
leading: Icon(Icons.perm_device_information),
title: Text('How'),
trailing: Icon(Icons.arrow_right),
onTap: () {
//Navigator.pushNamed(context, "/how");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HowItWorks(),
));
},
),
ListTile(
leading: Icon(Icons.keyboard),
title: Text('Contact'),
trailing: Icon(Icons.arrow_right),
onTap: () {
//Navigator.pushNamed(context, "/contact");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SendMail(),
));
},
),
],
),
);
}
}