'bottom navigation bar: Navigate back to nav bar item from any screen in the app / Navigator.pushNamed instead of creating an object instance flutter
I would like to use Navigator.pushNamed(context, '/route-name'); instead of creating an object instance. I'm trying to get back to a single instance of the called screen from multiple screens of the app. Is there any other way to make this possible? Thx for help!
I would like to replace the widget list with navigator routes instances so i can navigate back to my screen from any place in the app. Code below:
class _NavigationWrapperState extends State<NavigationWrapper> {
var bottomWidgetKey = GlobalKey<State<BottomNavigationBar>>();
int _index = 0;
List<Widget> widgets = [
MyIssuesOverview(),
ProjectOverview(),
DashboardWrapper(),
SettingsScreen(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
key: bottomWidgetKey,
body: widgets.elementAt(_index),
bottomNavigationBar: BottomNavigationBar(
selectedItemColor: Colors.blue,
unselectedItemColor: Colors.grey,
onTap: (int idx) => {
setState(() {
_index = idx;
}),
},
currentIndex: _index,
items: [
BottomNavigationBarItem(label: "Home", icon: Icon(Icons.home)),
BottomNavigationBarItem(label: "Projects", icon: Icon(Icons.topic)),
BottomNavigationBarItem(
label: "Dashboard",
icon: Icon(Icons.add_chart),
),
BottomNavigationBarItem(
label: "Timer",
icon: Icon(Icons.lock_clock),
),
BottomNavigationBarItem(
label: "Settings",
icon: Icon(Icons.settings),
)
],
),
);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|