BilalShahid13 / PersistentBottomNavBar

A highly customizable persistent bottom navigation bar for Flutter
BSD 3-Clause "New" or "Revised" License
524 stars 394 forks source link

Null check operator used on a null value on clicking center add nav bar item with NavBarStyle.style17 #237

Open y0unghe opened 3 years ago

y0unghe commented 3 years ago

Tap on the center add nav bar item, sometime this error show: Exception caught by gesture: Null check operator used on a null value

@override
  Widget build(BuildContext context) {
    return PersistentTabView(
      context,
      screens: [
        MessagePage(),
        DiscoverPage(),
        DummyPage(),
        RecommendListPage(),
        MyPage(),
      ],
      controller: _persistentTabController,
      items: [
        PersistentBottomNavBarItem(
          icon: Icon(Icons.message),
          activeColorPrimary: Colors.blue,
          inactiveColorPrimary: Colors.grey,
          inactiveColorSecondary: Colors.purple,
        ),
        PersistentBottomNavBarItem(
          icon: Icon(Icons.favorite),
          activeColorPrimary: Colors.teal,
          inactiveColorPrimary: Colors.grey,
        ),
        PersistentBottomNavBarItem(
            icon: Icon(Icons.add),
            activeColorPrimary: Values.hotPinkColor,
            activeColorSecondary: Colors.white,
            inactiveColorPrimary: Colors.white,
            onPressed: (context) {
              showModalBottomSheet(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(20.0),
                      topRight: Radius.circular(20.0),
                    ),
                  ),
                  backgroundColor: Colors.white,
                  builder: (context) {
                    return CustomBottomSheet(
                      action1: () async {
                        Navigator.of(context).pop();
                        Get.to(CreateMomentPage());
                      },
                      action2: () async {
                        Navigator.of(context).pop();
                      },
                    );
                  },
                  context: context!);
            }),
        PersistentBottomNavBarItem(
          icon: Icon(Icons.message),
          activeColorPrimary: Colors.deepOrange,
          inactiveColorPrimary: Colors.grey,
        ),
        PersistentBottomNavBarItem(
          icon: Icon(Icons.face),
          activeColorPrimary: Colors.indigo,
          inactiveColorPrimary: Colors.grey,
        ),
      ],
      confineInSafeArea: true,
      backgroundColor: Colors.white,
      handleAndroidBackButtonPress: true,
      resizeToAvoidBottomInset: true,
      stateManagement: true,
      navBarHeight: MediaQuery.of(context).viewInsets.bottom > 0
          ? 0.0
          : kBottomNavigationBarHeight,
      hideNavigationBarWhenKeyboardShows: true,
      margin: EdgeInsets.all(0.0),
      popActionScreens: PopActionScreensType.all,
      bottomScreenMargin: 0.0,
      selectedTabScreenContext: (context) {},
      decoration: NavBarDecoration(
          colorBehindNavBar: Colors.indigo,
          borderRadius: BorderRadius.circular(20.0)),
      popAllScreensOnTapOfSelectedTab: true,
      itemAnimationProperties: ItemAnimationProperties(
        duration: Duration(milliseconds: 400),
        curve: Curves.ease,
      ),
      screenTransitionAnimation: ScreenTransitionAnimation(
        animateTabTransition: true,
        curve: Curves.ease,
        duration: Duration(milliseconds: 200),
      ),
      navBarStyle:
          NavBarStyle.style17, // Choose the nav bar style with this property
    );
  }
Stratovarius93 commented 2 years ago

I have same problem

bschrdr commented 2 years ago

+1

IgorTurcan commented 1 year ago

Maybe this will help: https://stackoverflow.com/questions/74758416/persistent-bottom-nav-bar-not-working-properly