滚动后颤振ListView KeepAlive [英] flutter ListView KeepAlive after some scroll
问题描述
我要keepAlive
已经在ListView
中呈现的窗口小部件.我尝试使用ListView
类提供的addAutomaticKeepAlives:true
属性.
I want to keepAlive
my widgets which are already rendered in ListView
. I was tried with addAutomaticKeepAlives:true
properties which provide by ListView
class.
这是我使用的示例代码.由SliverList
提供的SliverChildBuilderDelegate
委托中存在相同的问题.
Here is my sample code which I was used. Same issue in SliverChildBuilderDelegate
delegate which provide by SliverList
.
ListView.builder(
itemBuilder: (context,index){
return Card(
child: Container(
child: Image.asset("images/${index+1}.jpg",fit: BoxFit.cover,),
height: 250.0,
),
);
},
addAutomaticKeepAlives: true,
itemCount:40 ,
);
推荐答案
要使automaticKeepAlive
正常工作,需要保持活动的每个项目都必须发送特定的通知.
For automaticKeepAlive
to work, each item that needs to be kept alive must send a specific notification.
触发此类通知的一种典型方法是使用 AutomaticKeepAliveClientMixin >
A typical way to fire such notification is using AutomaticKeepAliveClientMixin
class Foo extends StatefulWidget {
@override
FooState createState() {
return new FooState();
}
}
class FooState extends State<Foo> with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
return Container(
);
}
@override
bool get wantKeepAlive => true;
}
这篇关于滚动后颤振ListView KeepAlive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!