flutter - StatefulWidget项的Listview
问题描述
一旦 StatefulWidget 被释放,(item out of screen)如何获取 StatefulWidget 的状态?
我实际上设置了一个动画列表,但我认为这是同样的问题。可能更新列表可能会解决问题。但是怎么做?
我只想要相同的状态。
解决方案
您State
需要保留需要使用AutomaticKeepAliveClientMixin
的 .
这是一个例子:
class Foo extends StatefulWidget {
@override
FooState createState() {
super.build(context);
return new FooState();
}
}
class FooState extends State<Foo> with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
return Container(
);
}
@override
bool get wantKeepAlive => true;
}
Foo
即使这样的小部件将屏幕留在ListView
推荐阅读
- full-text-search - Couchbase 全文搜索特殊字符或重音
- javascript - 如何读取具有 node_modules 平面依赖关系的 npm 项目的源代码?
- python - 线性回归与随机森林的性能准确性
- r - 从 ioslides 中启用的高亮模式开始
- ios - 是否可以在应用程序中提供设置以让用户打开或关闭 Braze 通知?
- javascript - 将变量从 php 传递到 html / js
- spacy - 如何将匹配项添加为实体并将其可视化?
- laravel - 从 API 登录 Laravel 时出现错误 token_not_provided JWT
- ios - ContainerView 视图中的后退按钮不起作用
- java - 在 Mac 上使用 Maven 测试 Selenium