xuelongqy / flutter_easy_refresh

A flutter widget that provides pull-down refresh and pull-up load.
https://xuelongqy.github.io/flutter_easy_refresh/
MIT License
3.84k stars 628 forks source link

Not works well with NestedScrollView #758

Open webMing opened 10 months ago

webMing commented 10 months ago
@override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: tabs.length, //
        child: Scaffold(
            body: NestedScrollView(
          headerSliverBuilder: (context, innerBoxIsScrolled) {
            return [
              const SliverAppBar(
                centerTitle: true,
                title: Text('XXXX'),
                pinned: true,
                forceElevated: false,
              ),
               SliverToBoxAdapter(
               // child: HomeHeader(),
               child: Container(color: Colors.red,height: 300,width: double.infinity,),
              ),
              SliverOverlapAbsorber(
                handle:
                    NestedScrollView.sliverOverlapAbsorberHandleFor(context),
                sliver: SliverPersistentHeader(
                    pinned: true,
                    delegate: _MyDelegate(
                      height: 44,
                      child: TabBar(
                        indicatorSize: TabBarIndicatorSize.label,
                        tabs:
                            tabs.map((String name) => Tab(text: name)).toList(),
                      ),
                    )),
              ),
            ];
          },
          body: TabBarView(
            children: tabs.map((String name) {
              return SafeArea(
                top: false,
                child: Builder(
                  builder: (BuildContext context) {
                    return EasyRefresh(
                      child: CustomScrollView(
                        key: PageStorageKey<String>(name),
                        slivers: <Widget>[
                          SliverOverlapInjector(
                            handle:
                                NestedScrollView.sliverOverlapAbsorberHandleFor(
                                    context),
                          ),
                          SliverList.builder(
                            itemBuilder: (context, index) {
                              return const Text('adfkfdj');
                            },
                          )
                        ],
                      ),
                      onRefresh: () async {
                        Future.delayed(const Duration(seconds: 1));
                      },
                    );
                  },
                ),
              );
            }).toList(),
          ),
        )));
  }
}

cn:这里的下拉刷新是有问题的,有什么方法可以解决吗? 不想用官方提供的 nested scoll 的 demo 这样开发者会有更多的自由度, en:There is a problem with pull-down refresh here, is there any way to fix it? Do not want to use the official nested scoll demo, so that developers will have more freedom

xuelongqy commented 10 months ago

NestedScrollView很多问题在下拉刷新中无解。非必要不建议使用NestedScrollView

webMing commented 10 months ago

NestedScrollView很多问题在下拉刷新中无解。非必要不建议使用NestedScrollView

感觉出现这个问题和处理sliverOverlapAbsorber有关,但换成官方提供的 RefreshIndicator 是没有问题, 看了一下RefreshIndicator实现中也没有特殊处理通过特殊方式来处理类似sliverOverlapAbsorber的情况,也没有思路了