Implement Tabs with TabPage and CupertinoTabPage
mainRoutemaster supports nested navigation for tabs.
For Material Tabs:
- Define a
TabPagein yourRouteMap. Provide achild(the tab bar container) and a list ofpathsthat belong to this tab. - In your tab container widget, use
TabPage.of(context)to access thecontrollerandstacks. - Use
PageStackNavigator(stack: stack)to render the content for each tab.
For Cupertino Tabs:
- Define a
CupertinoTabPagein yourRouteMap. - In your tab container widget, use
CupertinoTabPage.of(context)to access thecontrollerandtabBuilder. - Use
CupertinoTabScaffoldto build the UI.
// TabPage Setup
RouteMap(
routes: {
'/': (route) => TabPage(
child: HomePage(),
paths: ['/feed', '/settings'],
),
'/feed': (route) => MaterialPage(child: FeedPage()),
'/settings': (route) => MaterialPage(child: SettingsPage()),
},
)
// HomePage implementation for TabPage
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final tabPage = TabPage.of(context);
return Scaffold(
appBar: AppBar(
bottom: TabBar(
controller: tabPage.controller,
tabs: [Tab(text: 'Feed'), Tab(text: 'Settings')],
),
),
body: TabBarView(
controller: tabPage.controller,
children: [
for (final stack in tabPage.stacks) PageStackNavigator(stack: stack),
],
),
);
}
}