一旦StatefulWidget处理完毕,(屏幕外的项目)如何检索StatefulWidget的状态?
我实际上设置了一个动画列表,但我认为这是相同的问题。可以通过更新列表来解决这个问题。但是怎么做呢?
我只想要同样的状态。
发布于 2019-09-25 21:49:50
为了使用AutomaticKeepAliveClientMixin,您需要保留需要保留的State。
下面是一个例子:
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;
}即使将屏幕留在ListView中,这样的Foo小部件也会保持其状态
https://stackoverflow.com/questions/58099911
复制相似问题