在 Flutter 中刷新小部件或页面,无需 ListView 等

eve*_*een 9 flutter flutter-animation

我想在没有可滚动内容的情况下刷新我的页面,即没有ListView等。

当我想使用时RefreshIndicator,文档说它需要一个scrollableListView.

但是,如果我想刷新,并希望使用的刷新动画RefreshIndicator不使用ListViewGridView或任何其他scorllable小部件,我该怎么办呢?

cre*_*not 7

您可以简单地将内容包装在 a 中SingleChildScrollView,这将允许您使用RefreshIndicator. 为了使下拉刷新交互工作,您必须使用,AlwaysScrollableScrollPhysics因为您的内容很可能不会比没有滚动视图的可用空间覆盖更多空间:

RefreshIndicator(
      onRefresh: () async {
        // Handle refresh.
      },
      child: SingleChildScrollView(
        physics: const AlwaysScrollableScrollPhysics(),
        child: /* your content */,
      ),
    );
Run Code Online (Sandbox Code Playgroud)