so I have a Drawer with currently two Drawer-Items leading to Page1 and Page2. Lets say I am currently on Page1. I can still press the Drawer-Item "Page1" and another "Page1" will be opened. I don#t want this to happen, therefore my question. How do I disable Drawer-Item "Page1" when I am currently on Page1 and Drawer-Item "Page2" if I am on Page2. Thank you in advance.
class PrimaryDrawer extends StatelessWidget {
const PrimaryDrawer({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
const DrawerHeader(
decoration: BoxDecoration(
color: Colors.blue,
),
child: Text('Drawer Header'),
),
ListTile(
title: const Text('Neuigkeiten'),
onTap: () {
Navigator.pop(context);
Navigator.push(context, MaterialPageRoute(builder: (context){
return const NewsPage(title: 'Neuigkeiten');
}));
},
),
ListTile(
title: const Text('Geburtstage'),
onTap: () {
Navigator.pop(context);
Navigator.push(context, MaterialPageRoute(builder: (context){
return const BirthdayPage(title: 'Geburtstage');
}));
},
),
],
),
);
}
}
Edit: So i added a code snippet, so whats bothering me is that If I am on the "NewsPage" and I open up the Drawer I can open up "NewsPage" again, I want to prohibit that. IDK if it even matters if there is the same page multiple times in the Route, but It just bothers me, probably a me thing i guess.
CodePudding user response:
before navigate to new Page2 close the Drawer
Navigator.pop(context);
CodePudding user response:
You can use provider to save your current page index and put condition while clicking on drawer item to check if its current page index is 1 then Page 1 will be not clickable and drawer is closed after the same