flutter tab切换页面防止重置


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

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

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

需要添加下面这个,如果没有analysis_options.yaml这个文件的话

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

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

方法二: 使用IndexedStack存储页面

_body = IndexedStack(
  children: <Widget>[
    BookHousePage(),
    FunctionPage(),
    ChatPage(),
    MinePage()
  ],
  index: _currentPageIndex,
);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM