【问题标题】:text in bottomNavigationBar is not appeared !!! flutterbottomNavigationBar 中的文字没有出现!!!扑
【发布时间】:2019-05-04 17:45:01
【问题描述】:

我是 Flutter 新手,我刚刚开发了我的第一个应用程序。所以,如果我的问题不清楚,请原谅我。

我现在正在处理底部导航栏。我用图标和文本制作了它,但只出现了第一个的图标和文本。其他唯一的图标。我怎样才能让所有出现?

这里是代码

bottomNavigationBar:  BottomNavigationBar(
        items: [
         BottomNavigationBarItem(
            icon: new Icon(Icons.home, color: Colors.black45),
            title: new Text(
              "الرئيسية",
              style: TextStyle(color: Colors.black45),
            )
        ),
         BottomNavigationBarItem(
            icon: new Icon(Icons.business, color: Colors.black45),
            title: new Text(
              "مرسال بيزنيس",
              style: TextStyle(color: Colors.black45),
            )),
         BottomNavigationBarItem(
            icon: new Icon(Icons.local_activity, color: Colors.black45),
            title: new Text(
              "أنشطة مرسال",
              style: TextStyle(color: Colors.black45),
            )),
         BottomNavigationBarItem(
            icon: new Icon(Icons.favorite_border, color: Colors.black45),
            title: new Text(
              "تبرع",
              style: TextStyle(color: Colors.black45),
            )),
         BottomNavigationBarItem(
            icon: new Icon(Icons.help, color: Colors.black45),
            title: new Text(
              "الأسئلة الشائعة",
              style: TextStyle(color: Colors.black45),
            ))
      ],
        onTap: (currentIndex){
          _currentIndex  = currentIndex;
          if(_currentIndex==0)
            Navigator.push(context,new MaterialPageRoute(builder: (context)=>new HomePage()));
          else if(_currentIndex==1)
            Navigator.push(context,new MaterialPageRoute(builder: (context)=>new business()));
          else if(_currentIndex==2)
            Navigator.push(context,new MaterialPageRoute(builder: (context)=>new activity()));
          else if(_currentIndex==3)
            Navigator.push(context,new MaterialPageRoute(builder: (context)=>new donate()));
          else if(_currentIndex==4)
            Navigator.push(context,new MaterialPageRoute(builder: (context)=>new faq()));

        },
      ),

这就是结果:

另一个问题:如何使活动项目具有不同的颜色?

【问题讨论】:

    标签: flutter


    【解决方案1】:

    你需要为你的 BottomNavigationBar 定义一个固定的类型

     bottomNavigationBar:  BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        selectedItemColor: Colors.red,
        unselectedItemColor: Colors.black45,
        currentIndex: 4,
    
    
        items: [
          BottomNavigationBarItem(
              icon: new Icon(Icons.home,/*color: Colors.black45*/),
              title: new Text(
                "الرئيسية",
                //style: TextStyle(color: Colors.black45),
              ),
          ),
          BottomNavigationBarItem(
              icon: new Icon(Icons.business, /*color: Colors.black45*/),
              title: new Text(
                "مرسال بيزنيس",
                //style: TextStyle(color: Colors.black45),
              )),
          BottomNavigationBarItem(
              icon: new Icon(Icons.local_activity, /*color: Colors.black45*/),
              title: new Text(
                "أنشطة مرسال",
               // style: TextStyle(color: Colors.black45),
              )),
          BottomNavigationBarItem(
              icon: new Icon(Icons.favorite_border, /*color: Colors.black45*/),
              title: new Text(
                "تبرع",
                //style: TextStyle(color: Colors.black45),
              )),
          BottomNavigationBarItem(
              icon: new Icon(Icons.help, /*color:  Colors.black45 */),
              title: new Text(
                "الأسئلة الشائعة",
                //style: TextStyle(color: Colors.black45),
              ))
        ],
    
      ),
    

    【讨论】:

    • 非常感谢它的工作(Y)...但是我怎样才能使活动项目具有不同的颜色??
    • 您需要删除您对 NavigationBar 施加的固定颜色样式并使用选定的项目颜色。请检查编辑后的代码بالتوفيق
    【解决方案2】:

    只需定义底部导航栏的类型,您就会看到文本。

      type: BottomNavigationBarType.fixed,
    

    提示:现在标题已被弃用,因此请使用标签属性而不是标题。

     BottomNavigationBarItem(
              icon: Icon(Icons.attach_email),
              label: "Emails",
              backgroundColor: Colors.yellow.shade900),
    

    【讨论】:

      【解决方案3】:

      我相信您可以对您的代码进行一些重构,以使其更具可读性和清洁性,而不是使用嵌套的 if,否则您可以像上面的代码那样做,确保类内部和 Widget Build 外部的 void 函数避免任何错误的功能。

       void onTabTapped(int index) {
          setState(() {
            _currentIndex = index;
          });
        }
      
      bottomNavigationBar:  BottomNavigationBar(
              items: [
               BottomNavigationBarItem(
                  icon: new Icon(Icons.home, color: Colors.black45),
                  title: new Text(
                    "الرئيسية",
                    style: TextStyle(color: Colors.black45),
                  )
              ),
               BottomNavigationBarItem(
                  icon: new Icon(Icons.business, color: Colors.black45),
                  title: new Text(
                    "مرسال بيزنيس",
                    style: TextStyle(color: Colors.black45),
                  )),
               BottomNavigationBarItem(
                  icon: new Icon(Icons.local_activity, color: Colors.black45),
                  title: new Text(
                    "أنشطة مرسال",
                    style: TextStyle(color: Colors.black45),
                  )),
               BottomNavigationBarItem(
                  icon: new Icon(Icons.favorite_border, color: Colors.black45),
                  title: new Text(
                    "تبرع",
                    style: TextStyle(color: Colors.black45),
                  )),
               BottomNavigationBarItem(
                  icon: new Icon(Icons.help, color: Colors.black45),
                  title: new Text(
                    "الأسئلة الشائعة",
                    style: TextStyle(color: Colors.black45),
                  ))
            ],
              onTap:onTabTapped,
            ),
      

      【讨论】:

        猜你喜欢
        • 2023-03-22
        • 2021-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-15
        • 2021-05-20
        • 2021-07-09
        • 1970-01-01
        相关资源
        最近更新 更多