使用bottomNavigationBar切换底部tab,再切换回来就会丢失之前的状态(重新渲染列表,丢失滚动条位置)。

解决方法

使用 AutomaticKeepAliveClientMixin

重写 bool get wantKeepAlive => true;

build方法中调用super.build(context);

class _MovieListState extends State<MovieList> with AutomaticKeepAliveClientMixin {
List movieList = new List(); @override
bool get wantKeepAlive => true; @override
Widget build(BuildContext context) {
super.build(context);
return ListView.builder(
itemCount: movieList.length,
itemBuilder: (context, index) {
return MovieItem(
item: movieList[index],
);
},
);
}
}

达到保存列表状态的效果

引用自官网的说明:

Subclasses must implement wantKeepAlive, and their build methods must call super.build (the return value will always return null, and should be ignored).

Then, whenever wantKeepAlive's value changes (or might change), the subclass should call updateKeepAlive.

The type argument T is the type of the StatefulWidget subclass of the State into which this class is being mixed.

参考链接:

AutomaticKeepAliveClientMixin mixin

最新文章

  1. 正则表达式之JSP、Android
  2. SSH框架 sequence diagram
  3. Windows 和  Linux 下 禁止ping的方法
  4. GenericRepository
  5. UTF-8编码规则
  6. Chapter 10 EF 6 Support
  7. 尝试一下用MARKDOWN嵌入代码
  8. 今天愉快的hack小记
  9. C语言基础文件读写操作
  10. SVN 版本控制工具
  11. 【Windows 10 应用开发】输入模拟
  12. spring BeanWrapperImpl方便的嵌套属性(list)操作
  13. Python中的序列操作
  14. css滚动条样式自定义
  15. 二、Oracle 数据库基本操作
  16. python描述器
  17. ES标准
  18. tomcat内存溢出设置JAVA_OPTS
  19. Eureka 高可用
  20. WP8.1学习系列(第十二章)——全景控件Panorama开发指南

热门文章

  1. 微弱信号二次谐波检测的FPGA的实现-总结
  2. vue element 关闭当前tab 跳转到上一路由
  3. baidumap 百度地图,实现多点之间的带方向路线图。
  4. h-index|IF|Good story|IPS
  5. webStrom 运行React-Native项目
  6. IDEA 中tomcat上面有个x 而且找不到配置tomcat的选项
  7. (转)假如没有OI By Vani
  8. 吴裕雄--天生自然python学习笔记:Python3 面向对象
  9. 科学家用AI看月球后,却发现了这些东西
  10. R内的gsub()函数