我想要keepAlive
我的小部件已经渲染在ListView
。我被尝试过addAutomaticKeepAlives:true
提供的属性ListView
class.
这是我使用的示例代码。同样的问题在SliverChildBuilderDelegate
代表提供者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 ,
);
For automaticKeepAlive
为了工作,需要保持活动的每个项目都必须发送特定的通知。
触发此类通知的典型方法是使用自动KeepAliveClientMixin https://api.flutter.dev/flutter/widgets/AutomaticKeepAliveClientMixin-mixin.html
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)