一些滚动后颤动 ListView KeepAlive [英] flutter ListView KeepAlive after some scroll
问题描述
我想 keepAlive
我已经在 ListView
中呈现的小部件.我尝试了 addAutomaticKeepAlives:true
属性,这些属性由 ListView
类提供.
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屋!