code example here :
last updated code
int _selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
Offstage(
offstage: _selectedIndex != 0,
child: TickerMode(
enabled: _selectedIndex == 0,
child: MaterialApp(
debugShowCheckedModeBanner: false, home:
NavigationBarTest()),
),
),
Offstage(
offstage: _selectedIndex != 1,
child: TickerMode(
enabled: _selectedIndex == 1,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: NavigationBarTest2()),
),
),
Offstage(
offstage: _selectedIndex != 2,
child: TickerMode(
enabled: _selectedIndex == 2,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: NavigationBarTest3()),
),
),
],
),
bottomNavigation_bar code ex:
bottomNavigationBar: NavigationBar(
destinations: const [
NavigationDestination(icon: Icon(Icons.home), label: 'home'),
NavigationDestination(icon: Icon(Icons.settings), label: 'setting'),
NavigationDestination(icon: Icon(Icons.person), label: 'profile')
],
selectedIndex: _selectedIndex,
onDestinationSelected: (int index) => setState(() {
_selectedIndex = index;
}),
animationDuration: const Duration(seconds: 1),
),
NavigationBarTest
class NavigationBarTest extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
color: Colors.amber,
);
}
}
class NavigationBarTest2 extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
color: Colors.red,
);
}
}
class NavigationBarTest3 extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
color: Colors.teal,
);
}
}