刷新指示器,无需滚动视图 [英] Refresh indicator without scrollview

查看:72
本文介绍了刷新指示器,无需滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用ListViewSingleChildScrollView RefreshIndicator只能在本机工作,但是我想在无法滚动的页面上使用RefreshIndicator.甚至有可能吗?如果可以,怎么办?

I know with a ListView or SingleChildScrollView RefreshIndicator just works natively but I want to use a RefreshIndicator on a page that doesn't scroll. Is this even possible and if so, how?

推荐答案

您必须执行以下操作:

  • 使用属性physics设置为AlwaysScrollableScrollPhysics()SingleChildScrollView.
  • 确保它的孩子的高度与屏幕大小相同,您可以通过MediaQuery.of(context).size.height来获得.
  • Use a SingleChildScrollView with the property physics set to AlwaysScrollableScrollPhysics().
  • Make sure it's child has a height of the size of the screen, which you can get with MediaQuery.of(context).size.height.

完整的示例:

classs MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RefreshIndicator(
      onRefresh: () {},
      child: SingleChildScrollView(
        physics: AlwaysScrollableScrollPhysics(),
        child: Container(
          child: Center(
            child: Text('Hello World'),
          ),
          height: MediaQuery.of(context).size.height,
        ),
      ),
    );
  }
}

这篇关于刷新指示器,无需滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆