peng8350 / flutter_pulltorefresh

a widget provided to the flutter scroll component drop-down refresh and pull up load.
MIT License
2.72k stars 721 forks source link

2.0.0null safety版本,报错「Don't use one refreshController to multiple SmartRefresher,It will cause some unexpected bugs mostly in TabBarView」 #483

Open wwpeng520 opened 3 years ago

wwpeng520 commented 3 years ago

包含底部多个bottomNavigationBar页面,其中一个页面使用SmartRefresher,初次进入改页面正常,从此页面跳到其他bottomNavigationBar页面,然后返回此页面报错

Don't use one refreshController to multiple SmartRefresher,It will cause some unexpected bugs mostly in TabBarView 'package:pull_to_refresh/src/smart_refresher.dart': Failed assertion: line 608 pos 12: '_refresherState == null'

1.6.4-nullsafety.0版本没有此错误

此页面之前不含TabBarView组件 主要代码如下:

return SmartRefresher(
  enablePullDown: true,
  enablePullUp: true,
  header: UIRefresherHeader(),
  footer: UIRefresherFooter(count: items.length, total: total),
  controller: controller.refreshController,
  onRefresh: controller.onRefresh,
  onLoading: controller.onLoading,
  child: items.length == 0
      ? UIRefresherEmpty()
      : ListView.builder(
    itemBuilder: (ctx, i) => ListItem(items[i]),
    itemCount: items.length,
  ),
);
devmfouad commented 3 years ago

any solution for this same problem with me after upgrade to flutter 2

peng8350 commented 3 years ago

this assert is intented.If you are sure that you only use one controller to one SmartRefresher.Please attach more details to reproduce bug.If you are using redux or fish redux,you may check if it is using by mutiple SmartRefresher at the same time.

devmfouad commented 3 years ago

i use provider pattern and i am using one controller before i upgrade to flutter 2 every thing run as expected but now after upgrade it's throw this error

peng8350 commented 3 years ago

@devmfouad Can you give an example code to reproduce(no third party library)?I have no time to check how to reproduce this,hope you can understand.

peng8350 commented 3 years ago

this issue example code doesn't show more details,so I don't know if this crash in a special stiuation or user fault.If user fault it need you to fix your code,if you don't know how to fix,I suggest you to stackoverflow,it contains many stiuation,I think his problem is redux global refreshController cause crash.If this crash in a special stiuation, I will revert it.

andoutica commented 3 years ago

I think this issue occurred when we refresh the whole widget. You can try using setstate{} to reproduce this issue.

syssam commented 3 years ago

same error when using PageView.builder and SmartRefresher after upgrade flutter 2.0

PageView.builder( itemBuilder: (context, position) { return return SmartRefresher(); }, itemCount: itemCount, )

peng8350 commented 3 years ago

If you are using PageView or TabBarView crash this.You may use one RefreshController to mutiple SmartRefresher I have said before.just like this.

this is a wrong doing

  RefreshController _refreshController = RefreshController();

 ...

return PageView.builder(
      itemBuilder: (context, position) {
         return SmartRefresher(
           controller: _refreshController[position],
           child: Container(color: Colors.white,),
         );
      },
      itemCount: 4,
    );

you need to fix code to work

 List<RefreshController> _refreshController = [RefreshController(),RefreshController(),RefreshController(),RefreshController()];

return PageView.builder(
      itemBuilder: (context, position) {
         return SmartRefresher(
           controller: _refreshController[position],
           child: Container(color: Colors.white,),
         );
      },
      itemCount: 4,
    );
syssam commented 3 years ago

noted with thanks, this will be better?

return PageView.builder(
      itemBuilder: (context, position) {
         final RefreshController _refreshController = RefreshController(initialRefresh: false);
         return SmartRefresher(
           controller: _refreshController ,
           child: Container(color: Colors.white,),
         );
      },
      itemCount: 4,
);
devmfouad commented 3 years ago

If you are using PageView or TabBarView crash this.You may use one RefreshController to mutiple SmartRefresher I have said before.just like this.

this is a wrong doing

  RefreshController _refreshController = RefreshController();

 ...

return PageView.builder(
      itemBuilder: (context, position) {
         return SmartRefresher(
           controller: _refreshController[position],
           child: Container(color: Colors.white,),
         );
      },
      itemCount: 4,
    );

you need to fix code to work

 List<RefreshController> _refreshController = [RefreshController(),RefreshController(),RefreshController(),RefreshController()];

return PageView.builder(
      itemBuilder: (context, position) {
         return SmartRefresher(
           controller: _refreshController[position],
           child: Container(color: Colors.white,),
         );
      },
      itemCount: 4,
    );

thanks this fix my problem

return PageView.builder( itemBuilder: (context, position) { final RefreshController _refreshController = RefreshController(initialRefresh: false); return SmartRefresher( controller: _refreshController[position], child: Container(color: Colors.white,), ); }, itemCount: 4, );

jahnli commented 3 years ago

@peng8350 I had the same problem
image image I only have one page of the BottomBar that uses the SmartreFresher