0

I am new to Flutter and Getx I created a bottom navigation bar but I am getting the error when I navigate to pages.

ERROR: Failed assertion: line 180 pos 7: 'positions.isNotEmpty': PageController.page cannot be accessed before a PageView is built with it

Here is my code:

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;
          }
          ),
        ),
     );
  }
}
Muhammad Usman
  • 2,419
  • 1
  • 11
  • 18

1 Answers1

0

You need to judge before using:

pageController?.positions?.isNotEmpty == true
                            ? _pageController?.page
                            : 0,
Zhuoyuan.Li
  • 318
  • 2
  • 10