79294645

Date: 2024-12-19 14:39:56
Score: 0.5
Natty:
Report link

code example here :

last updated code

enter image description here

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,
      );
     }
   }
Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Ahmed tharwat