flutter 报错:The provided ScrollController is currently attached to more than one

如题这个报错[ The provided ScrollController is currently attached to more than one ]是在 

页面出现滚动时候触发的,

页面滚动的 ScrollController 那里有

SingleChildScrollView / ListView  /  ListView.builder 里面有controller

这里报错意思是  ScrollController  控制了多个组件里面的滚动,

为啥会是多个 因为 页面嵌套 就出现这个情况了

解决方法: 给用到滚动的组件都见一个 controller, 就好了


例如:

late ScrollController _pageScrollerController;


  @override

  void initState() {

    super.initState();

    _pageScrollerController = ScrollController();

    realTimeBloc = RealTimeBloc();

  }

  @override

  void dispose() {

    realTimeBloc.close();

    _pageScrollerController .dispose();

    super.dispose();

  }

ListView.builder(

                  controller: _pageScrollerController ,

                  shrinkWrap: true, //范围内进行包裹(内容多高ListView就多高)

                  physics: NeverScrollableScrollPhysics(),

                  itemCount: state.rechargemodel?.rechargeInfo?.length,

                  itemBuilder: (context, index) {

                    return _tableRechargeRowData(state.rechargemodel?.rechargeInfo?[index]);

                  },

                ),

你可能感兴趣的:(flutter 报错:The provided ScrollController is currently attached to more than one)