Reputation: 25
I'm newbie with flutter
anyone can help me How to Reset Layout Page Drawer, After we Change the page and get back ?
this my code :
class DrawerItem {
String title;
IconData icon;
DrawerItem(this.title, this.icon);
}
class Homepage extends StatefulWidget {
Homepage({super.key});
final drawerItems = [
DrawerItem("Home", Icons.home),
DrawerItem("1", Icons.military_tech),
DrawerItem("2", Icons.paid),
DrawerItem("3", Icons.account_circle),
DrawerItem("4", Icons.volunteer_activism),
];
@override
State<Homepage> createState() => _HomepageState();
}
class _HomepageState extends State<Homepage> {
int _selectedDrawerIndex = 0;
_getDrawerItemWidget(int pos) {
if (pos == 1) {
return 1();
} else if (pos == 2) {
return 2();
} else {
return Text("Error");
}
}
_onSelectItem(int index) {
setState(() => _selectedDrawerIndex = index);
Navigator.of(context).pop(); // close the drawer
}
@override
Widget build(BuildContext context) {
List<Widget> drawerOptions = [];
for (var i = 0; i < widget.drawerItems.length; i++) {
var d = widget.drawerItems[i];
drawerOptions.add(ListTile(
leading: Icon(d.icon),
title: Text(d.title),
selected: i == _selectedDrawerIndex,
onTap: () => _onSelectItem(i),
));
}
return Scaffold(
appBar: AppBar(
title: Text(widget.drawerItems[_selectedDrawerIndex].title),
),
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
SizedBox(
height: 150,
child: const DrawerHeader(
decoration: BoxDecoration(color: Colors.blue),
child: Text('Aplikasi Perhitungan',
style: TextStyle(color: Colors.white, fontSize: 24)),
),
),
Column(children: drawerOptions)
],
),
),
body: _getDrawerItemWidget(_selectedDrawerIndex),
);
}
}
in Page 1 I have Some input form, when I select the first form, another form will display, this the picture : Drawer menu
can anyone help me, how to reset the layout when I Use the Page 1, go to home page, and then go back to page 1, layout from picture 2 will back like picture 1
I'm already setstate in file page 1, but nothing happend
Upvotes: 0
Views: 18