For mobile applications requiring tabbed navigation, use AutoTabsRouter. Unlike a standard AutoRouter (which is a shortcut for AutoStackRouter and manages a stack of pages), AutoTabsRouter preserves the state of offstage routes and allows for custom transition animations.
By default, tab routes are lazily loaded, though this can be disabled. You can use the builder property to access the TabsRouter controller via AutoTabsRouter.of(context) to manage the active index.
class DashboardPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AutoTabsRouter(
// list of your tab routes
// routes used here must be declared as children
routes: const [
UsersRoute(),
PostsRoute(),
SettingsRoute(),
],
transitionBuilder: (context,child,animation) => FadeTransition(
opacity: animation,
child: child,
),
builder: (context, child) {
final tabsRouter = AutoTabsRouter.of(context);
return Scaffold(
body: child,
bottomNavigationBar: BottomNavigationBar(
currentIndex: tabsRouter.activeIndex,
onTap: (index) {
tabsRouter.setActiveIndex(index);
},
items: [
BottomNavigationBarItem(label: 'Users', ...),
BottomNavigationBarItem(label: 'Posts', ...),
BottomNavigationBarItem(label: 'Settings', ...),
],
),
);
},
);
}
}