我正在使用flutter进行导航,但是如果我点击后退按钮并且myLocationEnabled等于true,我的应用程序就会一直崩溃,但是如果我将其值设置为false,崩溃问题就会消失。所以我想出了一个主意,如果我点击后退按钮,使用WillPop将其值设置为false,但是这样做之后它又崩溃了。有人能检查一下我的逻辑是否正确吗?
这是终端崩溃后的信息
F/libc(15924):致命信号11(SIGSEGV),代码1(SEGV_MAPERR),tid 16574(GLThread 7795)中的故障地址0x 0,pid 15924(示例项目)
构建指纹:“红米/兰斯洛特_全球/兰斯洛特:10/QP1A.190711.020/V12.0.4.0.QJCMIXM:用户/释放键”
bool location = true;
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
Navigator.pop(context);
setState(() {
location = false;
});
return true;
},
child: Scaffold(
appBar: AppBar(
title: const Text('Restaurants Map'),
),
body: SafeArea(
child: Stack(
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 1,
child: MapboxMap(
accessToken: dotenv.env['MAPBOX_ACCESS_TOKEN'],
initialCameraPosition: _initialCameraPosition,
onMapCreated: _onMapCreated,
onStyleLoadedCallback: _onStyleLoadedCallback,
//if this is false it will not crash if I tap the back button
myLocationEnabled: location,
myLocationTrackingMode: MyLocationTrackingMode.TrackingGPS,
minMaxZoomPreference: const MinMaxZoomPreference(14, 17),
),
),
CarouselSlider(
items: carouselItems,
options: CarouselOptions(
height: 105,
viewportFraction: 0.6,
initialPage: 0,
enableInfiniteScroll: false,
scrollDirection: Axis.horizontal,
onPageChanged:
(int index, CarouselPageChangedReason reason) {
setState(() {
pageIndex = index;
});
_addSourceAndLineLayer(index, true);
}))
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
controller.animateCamera(
CameraUpdate.newCameraPosition(_initialCameraPosition));
},
child: const Icon(Icons.my_location),
),
),
);
}
2条答案
按热度按时间ajsxfq5m1#
我已经修改了你的代码。使用
MapboxMap
类与以下属性。1sbrub3j2#
这很可能与Native crash in Flutter 3 #1119问题有关,该问题仍未解决...