构建底部导航条颤振时出错



我是新的扑动,我试图通过模仿一个应用程序学习,所以请不要打我太辛苦。首先,我有这样的main_page.dart。这是没有BottomNavigationBar,它工作得很好。我正在观看这个youtube视频来构建bottom nav bar,但是当我试图将main_page.dart包含到我的main.dart (which is the original MAIN dart file that comes initially中的HomePage()时,会出现这个错误。
所以这是我的BottomNavigationBar代码:

class bottomNavBar extends StatefulWidget {
const bottomNavBar({Key? key}) : super(key: key);
@override
State<bottomNavBar> createState() => _bottomNavBarState();
}
class _bottomNavBarState extends State<bottomNavBar> {
List pages = [
HomePage(),
activityMain(),
investMain(),
sendMain()
];
int currentIndex = 0;
void onTap(int index){
setState(() {
currentIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: pages[currentIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: onTap,
currentIndex: currentIndex,
backgroundColor: Color(0xFFF36A3B),
selectedItemColor: Colors.black54,
unselectedItemColor: Colors.grey.withOpacity(0.5),
showSelectedLabels: true,
showUnselectedLabels: true,
selectedFontSize: 10,
unselectedFontSize: 10,
elevation: 0,
items: [
BottomNavigationBarItem(label: 'Assets', icon: FaIcon(FontAwesomeIcons.wallet)),
BottomNavigationBarItem(label: 'Activity', icon: FaIcon(FontAwesomeIcons.userPlus)),
BottomNavigationBarItem(label: 'Invest', icon: FaIcon(FontAwesomeIcons.arrowTrendUp)),
BottomNavigationBarItem(label: 'Send', icon: FaIcon(FontAwesomeIcons.solidPaperPlane))
],
),
);
}
}

我不太明白这个错误,但通常在生成包含三个以上项目的底部导航栏时存在一个问题,只需将类型定义为固定的,如下所示:

bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
...

最新更新