Flutter RefreshIndicator 不适用于 TabBar 和 NestedScrollView

问题描述 投票:0回答:2

我的应用程序未按预期运行,我希望当我向下滚动应用程序时,它将显示刷新指示器并刷新页面。但现在当我向下滚动屏幕时,什么也没有发生。这是我的代码结构

return RefreshIndicator(
                backgroundColor: Colors.white,
                onRefresh: refreshPage,
                child: Stack(
                  children: <Widget>[
                    Container(
                      padding: EdgeInsets.only(bottom: 60),
                      child: NestedScrollView(
                        controller: _scrollController,
                        physics: ClampingScrollPhysics(),
                        headerSliverBuilder: (context, value) {
                          return [
                            SliverToBoxAdapter(
                              child: SomeWidget(),
                            ),
                            SliverToBoxAdapter(
                              child: SomeWidget(),
                            ),
                            SliverToBoxAdapter(
                              child: SomeWidget(),
                            ),
                            SliverToBoxAdapter(
                              child: SomeWidget(),
                            ),
                            SliverToBoxAdapter(
                              child: DefaultTabController(
                                length: 2,
                                child: TabBar(
                                  tabs: [
                                    Tab(text: "tab1"),
                                    Tab(text: "tab2"),
                                  ],
                                  controller: _tabController,
                                ),
                              ),
                            ),
                          ];
                        },
                        body: TabBarView(
                           controller: _tabController,
                           children: [
                              WidgetContentTab1(),
                              WidgetContentTab2(),
                           ],
                        physics: NeverScrollableScrollPhysics(),
                        );
                      ),
                    ),
                  ],
                ),
              );

哪部分需要修复?

android flutter mobile
2个回答
3
投票

尝试添加这些行。

notificationPredicate: (notification) => notification.metrics.axisDirection == AxisDirection.down,

还有

physics: const AlwaysScrollableScrollPhysics(),

例如

RefreshIndicator(
    notificationPredicate: (notification) => notification.metrics.axisDirection == AxisDirection.down,
    onRefresh: () => Future.delayed(const Duration(seconds: 2)),
    child: ListView(
        physics: const AlwaysScrollableScrollPhysics(),
        ...
}

1
投票

我看到你正在使用

ClampingScrollPhysics

针对防止滚动偏移超出内容边界的环境的滚动物理。

BouncingScrollPhysics

滚动物理环境允许滚动偏移超出内容的边界,但随后将内容弹回这些边界的边缘。

你可以尝试改变滚动物理

© www.soinside.com 2019 - 2024. All rights reserved.