Flutter中BottomNavigationBarItem的title属性失效报错求助
在新版Flutter中,BottomNavigationBarItem的title属性已被废弃,官方要求使用label属性替代,这就是你代码报错的核心原因。
修正后的代码如下:
bottomNavigationBar: BottomNavigationBar( items: const <BottomNavigationBarItem>[ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Home', // 替换原title属性 ), BottomNavigationBarItem( icon: Icon(Icons.message), label: 'Messages', ), BottomNavigationBarItem( icon: Icon(Icons.person), label: 'Profile', ), ], ),
如果需要自定义底部导航文字的样式,可以通过BottomNavigationBar的labelStyle属性统一设置:
bottomNavigationBar: BottomNavigationBar( labelStyle: TextStyle(fontSize: 14, fontWeight: FontWeight.w500), // 自定义文字样式 items: const <BottomNavigationBarItem>[ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Home', ), // 其他导航项... ], ),
内容的提问来源于stack exchange,提问作者Chamithu Dinsara
相关产品推荐
相关产品推荐

