一些滚动后颤动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.
这是我使用的示例代码.SliverChildBuilderDelegate
委托中的相同问题,由 SliverList
提供.
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.
触发此类通知的典型方法是使用 AutomaticKeepAliveClientMixinp>
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屋!