只有在我的华为p10+上测试flutter应用程序时才会发生此错误。我的应用程序在一个提醒对话框上加载谷歌地图。Map可以加载几次,然后随机失败。但我注意到Googlemap在失败时无法加载到alertdialog容器中。这是我的代码:
_loadMapDialog() {
try {
if (_currentPosition.latitude == null) {
Toast.show("Location not available. Please wait...", context,
duration: Toast.LENGTH_LONG, gravity: Toast.BOTTOM);
_getLocation(); //_getCurrentLocation();
return;
}
_controller = Completer();
_userpos = CameraPosition(
target: LatLng(latitude, longitude),
zoom: 14.4746,
);
markers.add(Marker(
markerId: markerId1,
position: LatLng(latitude, longitude),
infoWindow: InfoWindow(
title: 'Current Location',
snippet: 'Delivery Location',
)));
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, newSetState) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
title: Text("Select Your Location"),
titlePadding: EdgeInsets.all(5),
//content: Text(curaddress),
actions: <Widget>[
Text(curaddress),
Container(
height: screenHeight / 2 ?? 600,
width: screenWidth ?? 360,
child: GoogleMap(
mapType: MapType.normal,
initialCameraPosition: _userpos,
markers: markers.toSet(),
onMapCreated: (controller) {
_controller.complete(controller);
},
onTap: (newLatLng) {
_loadLoc(newLatLng, newSetState);
}),
),
MaterialButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)),
//minWidth: 200,
height: 30,
child: Text('Close'),
color: Colors.blue[500],
textColor: Colors.white,
elevation: 10,
onPressed: () =>
{markers.clear(), Navigator.of(context).pop(false)},
),
],
);
},
);
},
);
} catch (e) {
print(e);
return;
}
}
调试控制台产生以下错误
D/mali_winsys(10015): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
I/HiTouch_HiTouchSensor(10015): HiTouch restricted: Sub windows restricted.
D/HiTouch_PressGestureDetector(10015): onAttached, package=com.slumberjer.myappt, windowType=2037, mHiTouchRestricted=true
D/mali_winsys(10015): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
D/mali_winsys(10015): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
W/libEGL (10015): EGLNativeWindowType 0x6ff5f79010 disconnect failed
D/mali_winsys(10015): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
D/AndroidRuntime( 9587): Shutting down VM
E/AndroidRuntime( 9587): FATAL EXCEPTION: main
E/AndroidRuntime( 9587): Process: com.slumberjer.myappt, PID: 9587
E/AndroidRuntime( 9587): java.lang.NullPointerException: Attempt to invoke virtual method
'android.view.DisplayAdjustments android.view.Display.getDisplayAdjustments()' on a null object reference
E/AndroidRuntime( 9587): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1636)
E/AndroidRuntime( 9587): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7946)
E/AndroidRuntime( 9587): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1092)
E/AndroidRuntime( 9587): at android.view.Choreographer.doCallbacks(Choreographer.java:893)
E/AndroidRuntime( 9587): at android.view.Choreographer.doFrame(Choreographer.java:812)
E/AndroidRuntime( 9587): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1078)
E/AndroidRuntime( 9587): at android.os.Handler.handleCallback(Handler.java:907)
E/AndroidRuntime( 9587): at android.os.Handler.dispatchMessage(Handler.java:105)
E/AndroidRuntime( 9587): at android.os.Looper.loop(Looper.java:216)
E/AndroidRuntime( 9587): at android.app.ActivityThread.main(ActivityThread.java:7625)
E/AndroidRuntime( 9587): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9587): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
E/AndroidRuntime( 9587): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
W/System ( 9587): A resource failed to call release.
I/Process ( 9587): Sending signal. PID: 9587 SIG: 9
Lost connection to device.
Exited (sigterm)
在华为手机以外的不同设备上测试相同的代码似乎效果不错。如果这个错误似乎与设备有关,有什么解决方法吗。
华为不支持谷歌地图。您必须切换到另一个地图提供商,例如。https://pub.dev/packages/huawei_map