我是 Flutter 和 Getx 的新手,我创建了一个底部导航栏,但导航到页面时出现错误。
错误:断言失败:第 180 行 pos 7:'positions.isNotEmpty':PageController.page 在使用它构建 PageView 之前无法访问
这是我的代码:
class BottomNavBar extends StatelessWidget {
final HomeController homeController = Get.put(new HomeController());
Widget callPage(int current) {
switch (current) {
case 0:
return new Home();
break;
case 1:
return new market();
break;
case 2:
return new setting();
break;
case 3:
return new news();
break;
case 4:
return new Wallet();
break;
default:
return new Home();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Obx(
() => Center(
child: callPage(homeController.selectedNavIndex),
),
),
bottomNavigationBar: Obx(
() => BottomNavigationBar(
type: BottomNavigationBarType.fixed,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: "Home",
),
BottomNavigationBarItem(
icon: Icon(Icons.leaderboard),
label: "Markets",
),
BottomNavigationBarItem(
icon: Icon(Icons.insights),
label: "Trades",
),
BottomNavigationBarItem(
icon: Icon(Icons.library_books),
label: "News",
),
BottomNavigationBarItem(
icon: Icon(Icons.account_balance_wallet),
label: "Wallets",
),
],
currentIndex: homeController.selectedNavIndex,
onTap: (index) {
homeController.selectedNavIndex = index;
}
),
),
);
}
}