bottommultinavigationbar 1.2.1 bottommultinavigationbar: ^1.2.1 copied to clipboard
A widget where each fragment has their own navigation history inside the bottom navigation bar
bottommultinavigationbar #
A widget where each fragment has their own navigation history inside the bottom navigation bar
Getting Started #
1. import bottommultinavigationbar #
import 'package:bottommultinavigationbar/bottommultinavigationbar.dart';
copied to clipboard
2. Create a list of PageNavigators: #
var pages = [
PageNavigator(
bottomNavigationIcon: Icon(Icons.ac_unit),
bottomNavigationText: "Page 1",
initialRoute: "/page2",
onGenerateRoute: (settings) {
if(settings.name == PageNavigator.home)
return MaterialPageRoute(builder: (_) => Test(test:"Page 1 - 1",index: 0,));
if(settings.name == "/page2")
return MaterialPageRoute(builder: (_) => Test(test:"Page 1 - 2",index: 0));
}
),
PageNavigator(
bottomNavigationIcon: Icon(Icons.ac_unit),
bottomNavigationText: "Page 2",
onGenerateRoute: (settings) {
if(settings.name == PageNavigator.home)
return MaterialPageRoute(builder: (_) => Test(test:"Page 2 - 1",index: 1,));
if(settings.name == "/page2-2")
return MaterialPageRoute(builder: (_) => Test(test:"Page 2 - 2",index: 1,));
}
),
];
copied to clipboard
Be sure that you use "/" in your namings like "/page1". PageNavigator.home represents the home page of the fragment. From there the navigator will navigate to your pages inside of the fragment without leaving the bottom navigation view. With the "initialRoute" attribute you can specify a different start point for each of your fragment.
3. Use the BottomMultiNavigationBar Widget #
@override
Widget build(BuildContext context) {
return BottomMultiNavigationBar(
index: myCounter
pageNavigators: pages,
onIndexChanged: (index) {
setState({
myCounter = index
})
},
);
}
copied to clipboard
4. Navigate #
You can use the Navigator.of(context).pushNamed() as usual
Navigator.of(context).pushNamed("/page2")
copied to clipboard
With passing data:
//push your data
Navigator.of(context).pushNamed("/page2-2",arguments: "Test data")
//in your PageNavigator
PageNavigator(
bottomNavigationIcon: Icon(Icons.ac_unit),
bottomNavigationText: "Page 2",
onGenerateRoute: (settings) {
if(settings.name == PageNavigator.home)
return MaterialPageRoute(builder: (_) => Test(test: "page2-1",index: 1,));
if(settings.name == "/page2-2")
if(settings.arguments is String)
return MaterialPageRoute(builder: (_) => Test(test: settings.arguments,index: 1,));
//else error handling
}
),
copied to clipboard