ScrollController not attached to any scroll views

前端 未结 11 1173
难免孤独
难免孤独 2021-01-17 07:22

I\'m using CustomScrollView, and providing it with a controller. ScrollController works, I even added a listener to it and print out the position of the scroll view.

11条回答
  •  心在旅途
    2021-01-17 07:48

    Delaying it is not the right solution. Better to wait till the tree is done building by using

    WidgetsBinding.instance
            .addPostFrameCallback((_){});
    

    sample

    WidgetsBinding.instance.addPostFrameCallback((_) {
          if(pageController.hasClients){
                  pageController.animateToPage(page index, duration: Duration(milliseconds: 1), curve: Curves.easeInOut);
          }
    });
    

提交回复
热议问题