Map shows fine, but does not show marker.
When you add a new marker when map finished loading and idling, the marker shows.
When you add a delay to addSymbol inside "onMapCreated" like below, it then shows the symbol:
Future.delayed(Duration(milliseconds: 1500), () {
mapController.addSymbol(
SymbolOptions(
geometry: LatLng(widget.post.lat, widget.post.long),
iconImage: "airport-15",
iconSize: 5,
),
);
});
How do we know or are suppose to handle the wait for onStyleCallBack?
This is the error that comes up when you don't add the delay:
Attempt to invoke virtual method 'java.util.List com.mapbox.mapboxsdk.plugins.annotation.SymbolManager.create(java.util.List)' on a null object reference
Works perfectly on iOS without any delays.
Same behaviour on device and emulator.
Version: mapbox_gl: ^0.9.0
Code:
onMapCreated: (MapboxMapController controller) async {
controller.addSymbol(
SymbolOptions(
geometry: LatLng(widget.post.lat, widget.post.long),
iconImage: "airport-15",
iconSize: 5,
),
);
},
Full output:
E/MapboxMapBuilder(11157): setCameraTargetBounds is supported only after map initiated.
I/Mbgl-EGLConfigChooser(11157): In emulator: true
D/HostConnection(11157): HostConnection::get() New Host Connection established 0xdfd4d000, enter code heretid 14985
D/HostConnection(11157): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0
D/EGL_emulation(11157): eglMakeCurrent: 0xdfd1aae0: ver 3 0 (tinfo 0xc70ab560)
D/eglCodecCommon(11157): setVertexArrayObject: set vao to 0 (0) 0 0
D/EGL_emulation(11157): eglCreateContext: 0xdfd1b740: maj 3 min 0 rcv 3
D/EGL_emulation(11157): eglMakeCurrent: 0xdfd1b740: ver 3 0 (tinfo 0xdfdc3920)
D/eglCodecCommon(11157): setVertexArrayObject: set vao to 0 (0) 3 0
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): Failed to handle method call
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.mapbox.mapboxsdk.plugins.annotation.SymbolManager.create(java.util.List)' on a null object reference
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at com.mapbox.mapboxgl.MapboxMapController.onMethodCall(MapboxMapController.java:648)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#plugins.flutter.io/mapbox_maps_5(11157): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/flutter (11157): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'java.util.List com.mapbox.mapboxsdk.plugins.annotation.SymbolManager.create(java.util.List)' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.mapbox.mapboxsdk.plugins.annotation.SymbolManager.create(java.util.List)' on a null object reference
E/flutter (11157): at com.mapbox.mapboxgl.MapboxMapController.onMethodCall(MapboxMapController.java:648)
E/flutter (11157): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter (11157): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/flutter (11157): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/flutter (11157): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter (11157): at android.os.MessageQueue.next(MessageQueue.java:336)
E/flutter (11157): at android.os.Looper.loop(Looper.java:174)
E/flutter (11157): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/flutter (11157): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (11157): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
question from:
https://stackoverflow.com/questions/65882522/re-mapbox-package-flutter-how-should-we-wait-know-if-onstyleloadedcallback-i 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…