StatefulWidget项目的Listview [英] Listview of item of StatefulWidget
本文介绍了StatefulWidget项目的Listview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一旦放置了StatefulWidget,(屏幕外的项目)如何获取StatefulWidget的状态?
Once the StatefulWidget dispose, (item out of screen) how to retrieve the state of the StatefulWidget?
我实际上是设置了一个动画列表,但是我认为这也是一个问题.可能会更新列表,可能会解决问题.但是如何?
I'm actually set a animatedlist but I think it's the same probleme. May be update the list might solved the probleme. But how?
我只想要相同的状态.
推荐答案
您需要保留需要保存的State
才能使用AutomaticKeepAliveClientMixin
.
You'll want the State
that needs to be preserved to use 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
Such Foo
widget will preserve its state even if it leaves the screen inside a ListView
这篇关于StatefulWidget项目的Listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文