flutter tab切换页面防止重置

问题描述:TabBar 配合TabBarView切换页面,而后每一个页面是一个listview加载数据,可是切换页面后listview的数据会被重置,git

从新被加载了,解决办法使用 with AutomaticKeepAliveClientMixin  实现  @protected bool get wantKeepAlive=>true; 便可,github

可能会出现红色报错,直接忽视spa

须要添加下面这个,若是没有analysis_options.yaml这个文件的话code

https://github.com/flutter/flutter/blob/master/analysis_options.yaml#L24blog

class _OpenLogListComponentState extends State<OpenLogListComponent> with AutomaticKeepAliveClientMixin{
 
  @protected
  bool get wantKeepAlive=>true;
  //其余逻辑
}

方法二: 使用IndexedStack存储页面get

_body = IndexedStack(
  children: <Widget>[
    BookHousePage(),
    FunctionPage(),
    ChatPage(),
    MinePage()
  ],
  index: _currentPageIndex,
);
相关文章
相关标签/搜索