【发布时间】:2019-05-11 21:06:47
【问题描述】:
我在物理 Android 设备 (Oneplus 6t) 上使用官方 google_maps_flutter 插件,自上次 Flutter 升级以来,我在调用 GoogleMap 小部件时出现黑屏。我目前在 master 分支上。任何帮助将不胜感激,谢谢。
插件版本 google_maps_flutter: ^0.0.3+3
复制代码
_buildScaffold(LatLng position){
Scaffold s = new Scaffold(
key: _scaffoldKey,
appBar: buildAppBar(context),
resizeToAvoidBottomPadding: false,
body:
new Padding(
padding: new EdgeInsets.all(8.0),
child: widget.viewSwitchManager.mapView
? new Column(
children: [
new Flexible(
child: new Stack(
children: <Widget>[
google_maps.GoogleMap(
onMapCreated: _onMapCreated,
options: google_maps.GoogleMapOptions(
mapType: google_maps.MapType.normal,
myLocationEnabled: true,
cameraPosition: google_maps.CameraPosition(
target: google_maps.LatLng(position.latitude,
position.longitude),
zoom: 11.0,
),
),
),
_showFloatingMapListButton(),
_showFloatingFiltersButton(),
]))
],
)
:
Stack(
children: <Widget>[
events != null ?
new Swiper(
loop: false,
itemBuilder: (BuildContext context, int index) {
EventTheTableLight event = events[index];
return EventSwiperCard(event: event);
},
itemCount: events.length,
viewportFraction: 0.8,
scale: 0.9,
) : SizedBox(),
_showFloatingMapListButton(),
_showFloatingFiltersButton(),
])
),
/*bottomNavigationBar: BottomAppBar(
child: new Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.filter_list),
onPressed: () {
_filtersBottomSheet();
}),
SizedBox(width: MediaQuery.of(context).size.width/1.8,),
IconButton(
icon: Icon(Icons.refresh),
onPressed: () {
refreshEvents();
}),
],
),
),*/
);
if(widget.viewSwitchManager.mapView && gMapController != null) {
_buildMarkers(position);
gMapController.onMarkerTapped.add(_onMarkerTapped);
}
//if (!_searched)
//_updateMapCenter(position, 13.0);
return s;
日志: java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法“double java.lang.Double.doubleValue()” E/MethodChannel#flutter/platform_views(29682):在 io.flutter.plugin.platform.PlatformViewsController.createPlatformView(PlatformViewsController.java:141) E/MethodChannel#flutter/platform_views(29682):在 io.flutter.plugin.platform.PlatformViewsController.onMethodCall(PlatformViewsController.java:118) E/MethodChannel#flutter/platform_views(29682):在 io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200) E/MethodChannel#flutter/platform_views(29682):在 io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163) E/MethodChannel#flutter/platform_views(29682):在 android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#flutter/platform_views(29682):在 android.os.MessageQueue.next(MessageQueue.java:326) E/MethodChannel#flutter/platform_views(29682): 在 android.os.Looper.loop(Looper.java:160) E/MethodChannel#flutter/platform_views(29682): 在 android.app.ActivityThread.main(ActivityThread.java:6863) E/MethodChannel#flutter/platform_views(29682):在 java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter/platform_views(29682):在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) E/MethodChannel#flutter/platform_views(29682): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
【问题讨论】:
-
如果您现在已经盯着这个 3 小时,您可能已经研究过这个,但我会检查 position 或 position.latitude/longitude 是否为空。 Dart 小数在 java 中是双精度数,您的跟踪提示为空 Double ...
-
不幸的是,lat 和 lon 不为空,但我认为问题在于 TargetPlatform 在某种程度上设置为 iOS ......我会继续调查并回信任何潜在的修复
-
解决方法(或者,至少,类似的东西):
if(LocalPlatform().isAndroid) debugDefaultTargetPlatformOverride = TargetPlatform.android; else debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
标签: android google-maps dart flutter