背景
我们是使用原生与Flutter混编的项目。在Flutter中有使用到高德地图。一直以来都有一个线程相关的crash问题,在页面销毁时,地图也会随之销毁,偶发性引发线程检查崩溃。
报错信息如下:
[VERBOSE-3:shared_thread_merger.cc(59)] Check failed: lease_term_ref > 0. lease_term should always be positive when merged, lease_term=0
修复
这个崩溃依赖于高德地图或Flutter官方修复,目前我这边优化处理了下,暂时做了规避。 在页面将要退出的时候主动先销毁地图组件,然后退出页面。
代码如下:
class _XXPageState extends State<XXPage> {
bool _willPop = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: KMAppBar(
'xx',
context: context,
onPressed: () => _pop(),
),
body: _willPop ? Container() : AMapWidget(),
);
}
void _pop() {
if (Platform.isIOS) {
setState(() {
_willPop = true;
});
Future.delayed(Duration(milliseconds: 50), (){
routerDelegate.pop();
});
} else {
routerDelegate.pop();
}
}
}