我将RefreshIndicator添加到了我的页面中,但是当 pull 刷新时,没有可见的指示器.代码如下:

class HomePage extends StatefulWidget {
  HomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<HomePage> {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: LocalGalleryTab(),
    );
  }
}

class LocalGalleryTab extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _LocalGalleryState();
  }
}

class _LocalGalleryState extends State<LocalGalleryTab> {
  @override
  Widget build(BuildContext context) {
    return new Container(child: new Center(
      child: new RefreshIndicator(
        child: Text("Local Gallery"),
        onRefresh: _refreshLocalGallery,
      ),
    ));
  }

  Future<Null> _refreshLocalGallery() async{
    print('refreshing stocks...');

  }
}

如何使用刷新指示器?Flutter doc没有给出太多的信息.

推荐答案

您需要在RefreshIndicator内添加滚动子项

enter image description here

class HomePage extends StatefulWidget {
  HomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<HomePage> {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: LocalGalleryTab(),
    );
  }
}

class LocalGalleryTab extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _LocalGalleryState();
  }
}

class _LocalGalleryState extends State<LocalGalleryTab> {
  @override
  Widget build(BuildContext context) {
    return new Container(child: new Center(
      child: new RefreshIndicator(
        child: ListView(
          children: List.generate(50,  (f) => Text("Item $f")),
        ),
        onRefresh: _refreshLocalGallery,
      ),
    ));
  }

  Future<Null> _refreshLocalGallery() async{
    print('refreshing stocks...');

  }
}

Flutter相关问答推荐

Flutter ReorderableListView在可滚动父级中无法完美工作

DART 3.3:为什么扩展类型不起作用?

摆动如何更改弹出菜单项高亮显示 colored颜色 半径

Ffmpeg_kit_fltter:^6.0.3版权问题

如何在Flutter 安全存储器中存储对象值?

上传的图像不能在FireBase中预览.S档案类型为空白,摆动

如何画三角形的圆角?

抖动问题:检测到0个或2个或更多具有相同值的[DropdownMenuItem]

如何手动将 FirebaseAuth 用户邮箱验证状态设置为 true

请求已在 flutter 中发送到 django 服务器,并且已返回响应,但条件仍然为 false

Select 文本时如何更改 Flutter 中的光标 colored颜色 ?

创建混合 TextWidget 和 TextFieldWidget

#Flutter/Riverpod - 使用 AsyncNotifier 时是否可以仅调用错误?

从所有设备注销,因为用户帐户已从 firebase flutter 中删除

我在手机上找不到我的 Flutter 应用缓存数据

如何获得Flutter 的时差?

如何在椭圆形图像周围添加边框?Flutter

构建失败 - 无法解析 io.grpc:grpc-core:[1.28.0]. (是的,我已经升级到 mavenCentral())

Flutter 用户过滤器

Flutter Firestore 数据库排序最近 24 小时内最喜欢的文档