0

I want to fix bottomNavigationBar on the hole of my application.

when I've changed the screen, bottomNavigationBar is disappears. so I want to fix in in hole of my app.

this is part of my code :

class MainPage extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
  supportedLocales: [
        const Locale('fa', 'iran'),
      ],
  );
  }
}
class MyNavigationBar extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyNavigationBar();
  }
}

class _MyNavigationBar extends State<MyNavigationBar> {
  int _selectedIndex = 0;
  int _currentIndex = 0;

  final String a= 'assets/icons/a.svg';
  final String b= 'assets/icons/b.svg';
  final String c= 'assets/icons/c.svg';
  final String d= 'assets/icons/d.svg';
  final String e= 'assets/icons/e.svg';

  List<Widget> _pages = [
    aScreen(),
    bScreen(),
    cScreen(),
    dScreen(),
  ];

  Stack _buildScreens() {
    List<Widget> children = [];
    _pages.asMap().forEach((index, value) {
      children.add(
        Offstage(
          offstage: _currentIndex != index,
          child: TickerMode(
            enabled: _currentIndex == index,
            child: value,
          ),
        ),
      );
    });

    return Stack(children: children);
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
  body: Center(
          child: _buildScreens(),
        ),
        bottomNavigationBar: Container(
          decoration: BoxDecoration(
            boxShadow: <BoxShadow>[
              BoxShadow(
                  color: Colors.black54,
                  blurRadius: 15.0,
                  offset: Offset(0.0, 0.75))
            ],
          ),
          child: BottomNavigationBar(
            currentIndex: _currentIndex,
            onTap: (index) {
              setState(() {
                _currentIndex = index;
              });
            },
            type: BottomNavigationBarType.fixed,
            unselectedLabelStyle: TextStyle(fontSize: 10.0, color: Colors.grey),
            selectedIconTheme: IconThemeData(, size: 10),
            selectedLabelStyle: TextStyle(color: Colors.grey),
            unselectedItemColor: Colors.grey[900],
            iconSize: 24,
            selectedFontSize: 10,

            items: <BottomNavigationBarItem>[
              BottomNavigationBarItem(
                icon: Container(
                  child: SvgPicture.asset(
                    a,
                    width: 24,
                    height: 24,
                  ),
                ),
                activeIcon: Container(
                  child: SvgPicture.asset(
                    b,
                    width: 24,
                    height: 24,
                 
                  ),
                ),
              ),
              BottomNavigationBarItem(
                icon: Container(
                  child: SvgPicture.asset(
                    c,
                    width: 24,
                    height: 24,
                  ),
                ),
                activeIcon: Container(
                  child: SvgPicture.asset(
                    c,
                    width: 24,
                    height: 24,
                  
                  ),
                ),
              ),
              BottomNavigationBarItem(
                icon: Container(
                  child: SvgPicture.asset(
                    d,
                    width: 24,
                    height: 24,
                  ),
                ),
                activeIcon: Container(
                  child: SvgPicture.asset(
                    d,
                    width: 24,
                    height: 24,
                  
                  ),
                ),
              ),
              BottomNavigationBarItem(
                icon: Container(
                  // alignment: Alignment.center,
                  child: SvgPicture.asset(
                    e,
                    width: 24,
                    height: 24,
                  ),
                ),
                activeIcon: Container(
                  child: SvgPicture.asset(
                    e,
                    width: 24,
                    height: 24,
                
                  ),
                ),
          
              ),
            ],
          ),
        ));
  }
  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }
}
Hamed
  • 5,867
  • 4
  • 32
  • 56
siitaw
  • 107
  • 3
  • 12

1 Answers1

0

did you try something like this:

  Widget _buildScreens(int index) {
    switch (index) {
      case 0:
        return FirstPage();
      case 1:
        return SecondPage();
      ...

      default:
        return FirstPage();
    }
  }
Hamed
  • 5,867
  • 4
  • 32
  • 56