Flutter NotificationListener is not working

Viewed 33

I am using NotificationListener on two screens 1 screen contains only BottomNavBar and other screen contains scrollable content... i am trying to hide bottom nav bar labels when user scroll upwards... and on other screen i want to show and hide container on user scroll... ONLY 1 notification is working at a time.... i want both of them to work on same scroll here is the code of bottom nav bar class

 body: NotificationListener<UserScrollNotification>(
          onNotification: (notification) {
            final ScrollDirection direction = notification.direction;
            setState(() {
              if (direction == ScrollDirection.reverse) {
                _visible = false;
              } else if (direction == ScrollDirection.forward) {
                _visible = true;
              }
            });
            return true;
          },
          child: Center(
            child: widgetOptions.elementAt(widget.selectedIndex),
          ),
        ),

here i am showing and hiding lables

 showUnselectedLabels: _visible ? true : false,
      showSelectedLabels: _visible ? true : false,

here is another class where i am showing and hiding container on scroll

 Scaffold(
        body: NotificationListener<UserScrollNotification>(
          onNotification: (notification) {
            final ScrollDirection scrollDirection = notification.direction;
            setState(() {
              if (scrollDirection == ScrollDirection.forward) {
                _visible = false;
              } else if (scrollDirection == ScrollDirection.reverse) {
                _visible = true;
              }
            });
            return true;
          },

here i am showing and hiding container

StickyHeader(
                    header: _visible
                        ? Container(
                            color: Colors.white,
                            child: Padding(
                              padding: const EdgeInsets.all(15.0),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  categoryContainer(context, "Food",
                                      Colors.purple, Colors.white, Colors.grey),
                                  const SizedBox(
                                    width: 5,
                                  ),
                                  categoryContainer(context, "Fashion",
                                      Colors.white, Colors.black, Colors.grey),
                                  const SizedBox(
                                    width: 5,
                                  ),
                                  categoryContainer(context, "Beauty",
                                      Colors.white, Colors.black, Colors.grey),
                                ],
                              ),
                            ),
                          )
                        : Container(),

Only 1 NotificationListener either navbar lables or container... I want both of them to work... Please help

0 Answers
Related