Flutter Bottom Navigation bar Icon Color Not Changing. Is it Some kind of setState bug or somthing trouble with my code?

1,290

try this code below, insert this code just before the scaffold perntesis, also dont forget to insert the packacge.

 bottomNavigationBar: CurvedNavigationBar(
        color: Colors.black26,
        backgroundColor: Color(0xFFFFC5C5),
        buttonBackgroundColor: Colors.greenAccent,
        height: 50.0,
        animationCurve: Curves.bounceInOut,
        items: <Widget>[
          Icon(Icons.translate, size: 20, color: Colors.black),

          Icon(Icons.translate, size: 20, color: Colors.black),
          Icon(Icons.list, size: 20, color: Colors.black),
          Icon(Icons.account_balance, size: 20,
              color: Colors.black),
//            Icon(Icons.camera, size: 20, color: Colors.black),
        ],
        index: 2,
        animationDuration: Duration(milliseconds: 400),
        onTap: (index) {
          debugPrint("Curent index is $index");
        }
    )
Share:
1,290
gouranga bora
Author by

gouranga bora

Updated on December 23, 2022

Comments

  • gouranga bora
    gouranga bora over 1 year

    I am New to Flutter actually I am not a coder but I am trying to build an app that can do basic things like the sign-in page, sign up, user data showing to the screen, and also I can see each other profile from the app I Stuck in the Bottom Navigation bar here which I never thought that it would be hard to get through.
    instead of giving up, I decided to google around and come up with different results (some of them are hard to understand and confusing). I am trying to build a navigation bar that routs to different pages with minimum memory usage (efficient code)
    I am so confused and I don't know now what to do! please help another coder(if someone fixes this I am going to consider myself a coder, don't think too much)

      @override
      Widget build(BuildContext context) {
        PageController _pageController = PageController();
        final List<Widget> _tabs = [FeedPage(), ListingPage(), SettingPage()];
    
        int _selectedIndex = 0;
        void _onPageChanged(int index) {
          setState(() {                                //Is something wrong with my setState?
            _selectedIndex = index;
          });
        }
    
        void _onItemTapped(int _selectedIndex) {
          _pageController.jumpToPage(_selectedIndex);
        }
    
        return Scaffold(
          body: PageView(
            controller: _pageController,
            children: _tabs,
            onPageChanged: _onPageChanged,                         //Check it out
            physics: NeverScrollableScrollPhysics(),
          ),
          bottomNavigationBar: BottomNavigationBar(
            currentIndex: _selectedIndex,                          //I use this
            onTap: _onItemTapped,
            items: [
              BottomNavigationBarItem(
                icon: Icon(
                  Icons.home,
                ),
                title: Text("Home"),
              ),
              BottomNavigationBarItem(
                icon: Icon(
                  Icons.list,
                ),
                title: Text("List"),
              ),
              BottomNavigationBarItem(
                icon: Icon(
                  Icons.person,
                ),
                title: Text("Profile"),
              ),
            ],
          ),
        );
      }
    }
    //is this the code bugged? or something wrong in my flutter IED or something I am confused
    
    • Programmer_3
      Programmer_3 over 3 years
      Flutter is now in stable release so bug is in your code.
    • gouranga bora
      gouranga bora over 3 years
      would you help me to fix it? I am stuck in here
    • Programmer_3
      Programmer_3 over 3 years
      stackoverflow.com/questions/49307858/… see this will solve your problem