Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.3k views
in Technique[技术] by (71.8m points)

why the SmartRefresher does not work in flutter

Now I am using SmartRefresher to refresh my app when pull down article list, I add pull_to_refresh dependencies in pubspec.yaml like this:

pull_to_refresh: 1.6.3

and this is my code:

child: CupertinoScrollbar(
                    child: SmartRefresher(
                        onRefresh: _onRefresh,
                        enablePullUp: true,
                        enablePullDown: true,
                        header: WaterDropMaterialHeader(),
                        controller: _refreshController,
                        onLoading: _loadingMoreArticle,
                        footer: CustomFooter(
                          builder: (BuildContext context, LoadStatus mode) {
                            Widget body;
                            if (mode == LoadStatus.idle) {
                              body = Text("上拉加载更多");
                            } else if (mode == LoadStatus.loading) {
                              body = CupertinoActivityIndicator();
                            } else if (mode == LoadStatus.failed) {
                              body = Text("加载失败!点击重试!");
                            } else if (mode == LoadStatus.canLoading) {
                              body = Text("release to load more");
                            } else {
                              body = Text("No more Data");
                            }
                            return Container(
                              height: 55.0,
                              child: Center(child: body),
                            );
                          },
                        ),
                        child: CupertinoScrollbar(
                            child: CustomScrollView(
                          controller: scrollController,
                          slivers: <Widget>[
                            SliverOverlapInjector(
                              handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
                                context,
                              ),
                            ),
                            if (state.articleListState.articleIds != null && state.articleListState.articleIds.length > 0)
                              SliverPadding(
                                padding: const EdgeInsets.symmetric(vertical: 8.0),
                                sliver: viewService.buildComponent("articlelist"),
                              )
                          ],
                        )))));

but the UI does not contain any effect of SmartRefresher, the header shows nothing when pull, and the footer shows nothing when push up, am I missing something? what should I do to fix it? Now I am using macOS Catalina 10.15.7 and Android Studio 4.1.2.

$ dart --version
Dart SDK version: 2.10.2 (stable) (Tue Oct 13 15:50:27 2020 +0200) on "macos_x64"
(base)



$ ~/apps/flutter/bin/flutter --version
Flutter 1.22.5 ? channel stable ? https://github.com/flutter/flutter.git
Framework ? revision 7891006299 (7 weeks ago) ? 2020-12-10 11:54:40 -0800
Engine ? revision ae90085a84
Tools ? Dart 2.10.4
(base)

this is the header shows when pull down:

enter image description here

question from:https://stackoverflow.com/questions/65931277/why-the-smartrefresher-does-not-work-in-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The SmartRefresher needs to be higher up the widget tree than other scrolling widgets which will conflict/override the pull up/pull down action for the refresher. You can wrap your entire widget tree in a container(full width and height of the screen) and apply the SmartRefresher to that with everything else a child, or test out moving the refresher further up the widget tree.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...