Guys i created a function that listens to user scrolls. When a user scrolls down then the pageno should change to the page above the current one When the user scrolls up then the page should change to the previous page. 4 pages total Meaning when user is on page 1 and scrolls up he should go to page 2 When user is in page 2 he should go to page 1 when he scrolls down. Tha variable changes, the print screen works. Issue is that when i scroll, it calls the scroll function 3 times instead of once. This makes it jump from page 1 to 4. How can i make it so that the scroll function is called only once instead of 3 times whenever the user scrolls?

// the variables i use:
  final ScrollController _scrollController = ScrollController();
  bool page1 = true;
  bool page2 = false;
  bool page3 = false;
  bool page4 = false;
// the function
  return Scaffold(
      backgroundColor: bgcolor,
      body: NotificationListener<ScrollNotification>(
        onNotification: (scrollNotification) {

 //listens to the user scroll down
          if (_scrollController.position.userScrollDirection ==
              ScrollDirection.reverse) {
//increases page number by 1 based on current page

            if (pageno == 1) {
              setState(() {
                pageno = 2;
                print(pageno);
              });
            } else if (pageno == 2) {
              setState(() {
                pageno = 3;
                print(pageno);
              });
            } else if (pageno == 3) {
              setState(() {
                pageno = 4;
                print(pageno);
              });
            }

            //checks that the user scrolled up
          } else if (_scrollController.position.userScrollDirection ==
              ScrollDirection.forward) { 
            print('scrolled up');
            if (pageno == 4) { //reduces the page number by 1 based on currentpage 
              setState(() {
                pageno = 3;
                print(pageno);
              });
            } else if (pageno == 3) {
              setState(() {
                pageno = 2;
                print(pageno);
              });
            } else if (pageno == 2) {
              setState(() {
                pageno = 1;
                print(pageno);
              });
            }
            //setState function
          }
          return true;
        },
        child: ListView(
          controller: _scrollController,
          scrollDirection: Axis.vertical,
          children: <Widget>[ 
    //a bunch of stuff here..
    ```