1、Flutter编译报错,Tickers used by AnimationControllers should be disposed by calling dispose() on the AnimationController itself. Otherwise, the ticker will leak. Failed assertion: line 4182 pos 12: '_debugLifecycleState != _ElementLifecycle.defunct': is not true.
解决:flutter动画在退出时要及时释放资源,否则会导致内存泄露。
@override
void dispose() {
_controller.stop();
_controller.dispose();
super.dispose();
}
2、listview头部会出现一段空白区域
原因:listview底层默认设置了一个padding
解决:可以使用MediaQuery.removePadding来移除padding;当listview结合appBar时则不会出现padding
Widget _listView(BuildContext context){
return MediaQuery.removePadding(
removeTop: true,
context: context,
child: ListView.builder(
itemCount: 10,
itemBuilder: (context,index){
return _item(context,index);
},
),
);
}
本文探讨了Flutter中动画控制器资源未释放导致的内存泄露问题,并提供了妥善的dispose方法。同时,针对ListView头部空白的常见原因——默认padding,给出了使用 MediaQuery 解决方案。
1万+

被折叠的 条评论
为什么被折叠?



