Flutter TabView刷新问题 [英] Flutter tabview refresh issue

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

问题描述

我的main.dart中有一个TabBarView,每个选项卡都有一个类来显示内容(它的listview对象),当我在两个选项卡之间移动时,每次都会刷新listview页面,对于tabbarview来说是否正常?我不希望每次在选项卡之间切换时都会刷新。

I have a TabBarView in my main.dart and every tab got a class to show the content(it's listview object), when i go between the tabs, the listview page refresh everytime, is it normal for tabbarview? I don't expect it will refresh everytime when i go between the tabs.

这是我班上的问题吗?如何解决这个问题?

is it the problem my class? how to fix this? the code is something like this.

    class ListWidget extends StatefulWidget {
  final catID;

  ListWidget(this.catID);


  _ListWidgetState createState() => new _ListWidgetState(catID);
}

class _ListWidgetState extends State<ListWidget> {

  var catID;

  void initState() {
    super.initState();
    _fetchListData();
  }

  @override

  Widget build(BuildContext context) {
    // TODO: implement build

    return new Scaffold(.......
}


推荐答案

如果我对您的理解很好,那么您就抱怨刷新,因为在选项卡之间移动后,需要视图来保存其状态。有一个关于这个问题的未解决问题,并且有一种方法可以解决注释中提到的这个问题。

If I understood you well, you are complaining about the refreshing because you need the views to save their states after moving between tabs. There is an open issue on the subject and there is a way around this problem mentioned in the comments.

更新:

使用 AutomaticKeepAliveClientMixin 可以解决此问题,您可以了解更多信息在此文章中。

There is a workaround for this issue by using AutomaticKeepAliveClientMixin which you can learn more about in this article.

这篇关于Flutter TabView刷新问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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