When using the Flutter Scaffold.Drawer - is it possible to have the links in the Drawer change the content (Scaffold.body) on the page?
Similarly to having links in the navigation drawer change a Fragment in Android.
Here is a easy and efficient way to do this with Full example
class _MyPageState extends State<MyPage> {
Widget bodyWidget;
Widget drawer() {
return
}
Widget bodyFirst() {
return Container(
color: Colors.green, child: Center(child: Text("First Page")));
}
Widget bodySecond() {
return Container(
color: Colors.limeAccent, child: Center(child: Text("Second Page")));
}
Widget bodyThird() {
return Container(
color: Colors.lightBlueAccent,
child: Center(child: Text("Third Page")));
}
@override
void initState() {
super.initState();
bodyWidget = bodyFirst();
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: drawer(),
appBar: AppBar(title: Text("My App")),
body: bodyWidget,
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With