未定义命名参数“title”。颤振中的问题

问题描述 投票:0回答:2

问题

未定义命名参数“title”。颤振问题

代码:

 items: [
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              title: Text('Home'),
              backgroundColor: Colors.white,
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.chat),
              title: Text(
                'Chat',
              ),
              backgroundColor: Colors.white,
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.alarm_add),
              title: Text('Reminder'),
              backgroundColor: Colors.white,
            ),
            // BottomNavigationBarItem(
            //   icon: Icon(Icons.supervised_user_circle),
            //   title: Text(
            //     'Profile',
            //   ),
            //   backgroundColor: Colors.white,
            // ),
          ],
flutter dart
2个回答
5
投票

label
 上使用 title
 代替 
BottomNavigationBarItem

会像这样

 BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: 'Home',
              backgroundColor: Colors.white,
            ),

更多关于

BottomNavigationBar
BottomNavigationBarItem


0
投票

升级 Flutter 版本时会出现这种情况。从 null 安全性(Flutter 3+)开始,由于其他一些更改,BottomNavigationBarItem 的 'title' 参数替换为 'label' 措辞,因此以下代码:

BottomNavigationBarItem(
              icon: Icon(Icons.home),
              title: Text('Home'),
              backgroundColor: Colors.white,
            ),

应修改为:

BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: 'Home',
              backgroundColor: Colors.white,
            ),

请注意,新版本直接采用裸字符串而不是 Text() 元素。

© www.soinside.com 2019 - 2024. All rights reserved.