I´ve a problem with the BottomNavigationBar in Flutter . BottomNavigationBarItem: title is not working and there is error

huangapple go评论68阅读模式
英文:

I´ve a problem with the BottomNavigationBar in Flutter . BottomNavigationBarItem: title is not working and there is error

问题

这是发生的错误。

bottomNavigationBar: BottomNavigationBar(
  items: const <BottomNavigationBarItem>[
    BottomNavigationBarItem(
      icon: Icon(
        Icons.home,
      ),
      title: Text(
        '首页',
      ),
    ),
    BottomNavigationBarItem(
      icon: Icon(
        Icons.message,
      ),
      title: Text(
        '消息',
      ),
    ),
    BottomNavigationBarItem(
      icon: Icon(
        Icons.person,
      ),
      title: Text(
        '个人资料',
      ),
    ),
  ],
),

错误代码片段

帮助解决这个问题。

英文:

enter image description herethis is the error occur.

bottomNavigationBar: BottomNavigationBar(
  items: const &lt;BottomNavigationBarItem&gt;[
    BottomNavigationBarItem(
      icon: Icon(
        Icons.home,
      ),
      title: Text(
        &#39;Home&#39;,
      ),
    ),
    BottomNavigationBarItem(
      icon: Icon(
        Icons.message,
      ),
      title: Text(
        &#39;Messages&#39;,
      ),
    ),
    BottomNavigationBarItem(
      icon: Icon(
        Icons.person,
      ),
      title: Text(
        &#39;Profile&#39;,
      ),
    ),
  ],

),

enter image description here error code snippets

help for solve this problem.

答案1

得分: 0

问题是BottomNavigationBarItem中没有title属性,而是使用label

另外,第一张图片中的错误提示说label等于null

英文:

the problem is that there is no property title in the BottomNavigationBarItem, instead use label

also the error in the first picture says, that label is equal to null

答案2

得分: 0

底部导航栏项目中没有名为'title'的参数。您需要使用'label'来为BottomNavigationBarItem小部件提供文本,并直接使用字符串。

因此,更新后的代码将如下所示:

bottomNavigationBar: BottomNavigationBar(
  items: const <BottomNavigationBarItem>[
    BottomNavigationBarItem(
      icon: Icon(
        Icons.home,
      ),
      label: '首页',
    ),
    BottomNavigationBarItem(
      icon: Icon(
        Icons.message,
      ),
      label: '消息',
    ),
    BottomNavigationBarItem(
      icon: Icon(
        Icons.person,
      ),
      label: '个人资料',
    ),
  ],
)
英文:

Bro there's not parameter with name 'title' in the BottomNavigationBarItem. you need to use label for giving the text in the BottomNavigationBarItem widget and it aspects string directly.

So the updated code would look like this:

bottomNavigationBar: BottomNavigationBar(
    items: const &lt;BottomNavigationBarItem&gt;[
      BottomNavigationBarItem(
          icon: Icon(
            Icons.home,
          ),
          label: &#39;Home&#39;,
      ),
      BottomNavigationBarItem(
        icon: Icon(
          Icons.message,
        ),
        label: &#39;Messages&#39;,
      ),
      BottomNavigationBarItem(
        icon: Icon(
          Icons.person,
        ),
        label: &#39;Profile&#39;,
      ),
    ],
  ),

答案3

得分: 0

你应该使用"label"而不是"title"

I´ve a problem with the BottomNavigationBar in Flutter . BottomNavigationBarItem: title is not working and there is error

I´ve a problem with the BottomNavigationBar in Flutter . BottomNavigationBarItem: title is not working and there is error

英文:

You should use label instead of title

I´ve a problem with the BottomNavigationBar in Flutter . BottomNavigationBarItem: title is not working and there is error

I´ve a problem with the BottomNavigationBar in Flutter . BottomNavigationBarItem: title is not working and there is error

huangapple
  • 本文由 发表于 2023年6月29日 18:20:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580136.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定