I am Working on Flutter Foreground task facing an issue of not running code which i have worked can any one help me out to under stand problem - flutter

basically i am working on voice application which takes an input as voice and convert voice into text if any command like hello received it will resond with an answer in voice
i have used packages
flutter tts
flutter speach
for foreground i have used
https://medium.com/#burlakovv.ivan/simple-android-foreground-service-in-flutter-for-non-kotlin-developers-31607909a633
here is out put of console
I/flutter ( 2692): AppLifecycleState----------------------------------state: AppLifecycleState.inactive
E/eglCodecCommon( 2692): goldfish_dma_create_region: could not obtain fd to device! fd -1 errno=2
I/flutter ( 2692): AppLifecycleState----------------------------------state: AppLifecycleState.paused
I/flutter ( 2692): AppLifecycleState----------------------------------state: AppLifecycleState.detached
I/flutter ( 2692): false
I/flutter ( 2692): _MyAppState.activateSpeechRecognizer...
W/TextToSpeech( 2692): stop failed: not bound to TTS engine
W/TextToSpeech( 2692): shutdown failed: not bound to TTS engine
I/flutter ( 2692): Marco Has been Found++++++++++++++++++++++++++++++
D/FlutterSpeechPlugin( 2692): Current Locale : en_US
E/MethodChannel#com.flutter.speech_recognition( 2692): Failed to handle method call
E/MethodChannel#com.flutter.speech_recognition( 2692): java.lang.NullPointerException: Attempt to invoke interface method 'android.app.Activity io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding.getActivity()' on a null object reference
E/MethodChannel#com.flutter.speech_recognition( 2692): at com.flutter.speech_recognition.flutter_speech.FlutterSpeechRecognitionPlugin.onMethodCall(FlutterSpeechRecognitionPlugin.java:52)
E/MethodChannel#com.flutter.speech_recognition( 2692): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#com.flutter.speech_recognition( 2692): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#com.flutter.speech_recognition( 2692): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
E/MethodChannel#com.flutter.speech_recognition( 2692): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/MethodChannel#com.flutter.speech_recognition( 2692): at android.os.Handler.handleCallback(Handler.java:883)
E/MethodChannel#com.flutter.speech_recognition( 2692): at android.os.Handler.dispatchMessage(Handler.java:100)
E/MethodChannel#com.flutter.speech_recognition( 2692): at android.os.Looper.loop(Looper.java:214)
E/MethodChannel#com.flutter.speech_recognition( 2692): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#com.flutter.speech_recognition( 2692): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#com.flutter.speech_recognition( 2692): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#com.flutter.speech_recognition( 2692): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
W/FlutterJNI( 2692): Tried to send a platform message response, but FlutterJNI was detached from native C++. Could not send. Response ID: 15
I/Choreographer( 2692): Skipped 269 frames! The application may be doing too much work on its main thread.
E/MethodChannel#com.flutter.speech_recognition( 2692): Failed to handle method call
E/MethodChannel#com.flutter.speech_recognition( 2692): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.speech.SpeechRecognizer.stopListening()' on a null object reference
E/MethodChannel#com.flutter.speech_recognition( 2692): at com.flutter.speech_recognition.flutter_speech.FlutterSpeechRecognitionPlugin.onMethodCall(FlutterSpeechRecognitionPlugin.java:75)
E/MethodChannel#com.flutter.speech_recognition( 2692): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#com.flutter.speech_recognition( 2692): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#com.flutter.speech_recognition( 2692): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
E/MethodChannel#com.flutter.speech_recognition( 2692): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/MethodChannel#com.flutter.speech_recognition( 2692): at android.os.Handler.handleCallback(Handler.java:883)
E/MethodChannel#com.flutter.speech_recognition( 2692): at android.os.Handler.dispatchMessage(Handler.java:100)
E/MethodChannel#com.flutter.speech_recognition( 2692): at android.os.Looper.loop(Looper.java:214)
E/MethodChannel#com.flutter.speech_recognition( 2692): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#com.flutter.speech_recognition( 2692): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#com.flutter.speech_recognition( 2692): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#com.flutter.speech_recognition( 2692): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
W/FlutterJNI( 2692): Tried to send a platform message response, but FlutterJNI was detached from native C++. Could not send. Response ID: 16

Related

error when using better player in flutter

E/MethodChannel#better_player_channel: Failed to handle method call
java.lang.NullPointerException: MediaSource.Factory#setDrmSessionManagerProvider no longer handles null by instantiating a new DefaultDrmSessionManagerProvider. Explicitly construct and pass an instance in order to retain the old behavior.
at com.google.android.exoplayer2.util.Assertions.checkNotNull(Assertions.java:174)
at com.google.android.exoplayer2.source.ProgressiveMediaSource$Factory.setDrmSessionManagerProvider(ProgressiveMediaSource.java:186)
at com.jhomlala.better_player.BetterPlayer.buildMediaSource(BetterPlayer.kt:430)
at com.jhomlala.better_player.BetterPlayer.setDataSource(BetterPlayer.kt:196)
at com.jhomlala.better_player.BetterPlayerPlugin.setDataSource(BetterPlayerPlugin.kt:277)
at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:151)
at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:138)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
E/flutter: [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, MediaSource.Factory#setDrmSessionManagerProvider no longer handles null by instantiating a new DefaultDrmSessionManagerProvider. Explicitly construct and pass an instance in order to retain the old behavior., null, java.lang.NullPointerException: MediaSource.Factory#setDrmSessionManagerProvider no longer handles null by instantiating a new DefaultDrmSessionManagerProvider. Explicitly construct and pass an instance in order to retain the old behavior.
at com.google.android.exoplayer2.util.Assertions.checkNotNull(Assertions.java:174)
at com.google.android.exoplayer2.source.ProgressiveMediaSource$Factory.setDrmSessionManagerProvider(ProgressiveMediaSource.java:186)
at com.jhomlala.better_player.BetterPlayer.buildMediaSource(BetterPlayer.kt:430)
at com.jhomlala.better_player.BetterPlayer.setDataSource(BetterPlayer.kt:196)
at com.jhomlala.better_player.BetterPlayerPlugin.setDataSource(BetterPlayerPlugin.kt:277)
at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:151)
at com.jhomlala.better_player.BetterPlayerPlugin.onMethodCall(BetterPlayerPlugin.kt:138)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18)
#2 MethodChannelVideoPlayer.setDataSource (package:better_player/src/video_player/method_channel_video_player.dart:118:5)
#3 VideoPlayerController._setDataSource (package:better_player/src/video_player/video_player.dart:408:5)
#4 BetterPlayerController._setupDataSource (package:better_player/src/core/better_player_controller.dart:444:9)
#5 BetterPlayerController.setupDataSource (package:better_player/src/core/better_player_controller.dart:274:5)
I face this problem when I use better_player in flutter, It was work good but now show this problem .
Any one can help me

Flutter Firebase Machine Learning Custom model

I have a method thats called to load models but seems to crash every time I call it, I followed the documentation for it I believe so I dont understand why.
Future loadModel() async {
await FirebaseModelDownloader.instance
.getModel(
"Breed-Detector",
FirebaseModelDownloadType.latestModel,
FirebaseModelDownloadConditions(
iosAllowsCellularAccess: true,
iosAllowsBackgroundDownloading: false,
androidChargingRequired: false,
androidWifiRequired: false,
androidDeviceIdleRequired: false,
))
.then((customModel) async {
final localModelPath = customModel.file;
Tflite.close();
String res;
res = (await Tflite.loadModel(
model: localModelPath.toString(), labels: "assets/labels.txt"))!;
print("Models Loading status: ${res}");
});
}
I get the error
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Failed to load model, flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Breed-Detector/0', java.io.FileNotFoundException: flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Breed-Detector/0'
but I have the model uploaded
tried uploading a separate model and that seemed to try and download it at first but failed again.
/ModelFileDownloadSer( 7365): Need to download a new model.
D/ModelFileDownloadSer( 7365): Schedule a new downloading task: 64
D/ModelFileDownloadSer( 7365): Model downloaded successfully
D/ModelFileDownloadSer( 7365): Moving downloaded model from external storage to destination folder.
D/ModelFileDownloadSer( 7365): Moved the downloaded model to destination folder successfully: /data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Dog-Breeds
E/flutter ( 7365): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Failed to load model, flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Dog-Breeds/0', java.io.FileNotFoundException: flutter_assets/File: '/data/user/0/com.example.find_my_dog/no_backup/com.google.firebase.ml.custom.models/W0RFRkFVTFRd+MToyNjY1MDIxMjc4ODE6YW5kcm9pZDpjZjhiMjk0NjAwNWRjZGQ1ZjE5M2Q4/Dog-Breeds/0'
E/flutter ( 7365): at android.content.res.AssetManager.nativeOpenAssetFd(Native Method)
E/flutter ( 7365): at android.content.res.AssetManager.openFd(AssetManager.java:898)
E/flutter ( 7365): at sq.flutter.tflite.TflitePlugin.loadModel(TflitePlugin.java:210)
E/flutter ( 7365): at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:98)
E/flutter ( 7365): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter ( 7365): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter ( 7365): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
E/flutter ( 7365): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/flutter ( 7365): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter ( 7365): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter ( 7365): at android.os.Looper.loop(Looper.java:223)
E/flutter ( 7365): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/flutter ( 7365): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 7365): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/flutter ( 7365): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/flutter ( 7365): , null)

Flutter Runtime Error: PlatformException (PlatformException(error, Attempt to invoke virtual method 'boolean android.view.inputmethod

Exception has occurred.
PlatformException (PlatformException(error, Attempt to invoke virtual method 'boolean android.view.inputmethod.BaseInputConnection.setComposingRegion(int, int)' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.inputmethod.BaseInputConnection.setComposingRegion(int, int)' on a null object reference
at io.flutter.plugin.editing.ListenableEditingState.setComposingRange(ListenableEditingState.java:144)
at io.flutter.plugin.editing.ListenableEditingState.setEditingState(ListenableEditingState.java:161)
at io.flutter.plugin.editing.ListenableEditingState.(ListenableEditingState.java:64)
at io.flutter.plugin.editing.TextInputPlugin.setTextInputClient(TextInputPlugin.java:421)
at io.flutter.plugin.editing.TextInputPlugin$1.setClient(TextInputPlugin.java:135)
at io.flutter.embedding.engine.systemchannels.TextInputChannel$1.onMethodCall(TextInputChannel.java:75)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
))

Sslcommerz plugin not working on physical device or Release mode

I have implemented flutter_sslcommerz plugin on my project. It works well on my emulator while debugging, but it doesn't seem to work while tested on a physical device.
I called the SSLCommerzInitialization function placing the necessary parameters.
Here is the error below -
PlatformException(error, null, null, java.lang.NullPointerException
I/flutter (32042): at f.c.a.c.a.getStoreId(Unknown Source:3)
I/flutter (32042): at f.c.a.b.a.sslCommerzInitializatoin(Unknown Source:4)
I/flutter (32042): at f.c.a.a.onMethodCall(Unknown Source:106)
I/flutter (32042): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(Unknown Source:17)
I/flutter (32042): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(Unknown Source:18)
I/flutter (32042): at io.flutter.embedding.engine.dart.DartMessenger.a(Unknown Source:20)
I/flutter (32042): at io.flutter.embedding.engine.dart.DartMessenger.b(Unknown Source:0)
I/flutter (32042): at io.flutter.embedding.engine.dart.c.run(Unknown Source:12)
I/flutter (32042): at android.os.Handler.handleCallback(Handler.java:938)
I/flutter (32042): at android.os.Handler.dispatchMessage(Handler.java:99)
I/flutter (32042): at android.os.Looper.loopOnce(Looper.java:233)
I/flutter (32042): at android.os.Looper.loop(Looper.java:344)
I/flutter (32042): at android.app.ActivityThread.main(ActivityThread.java:8191)
I/flutter (32042): at java.lang.reflect.Method.invoke(Native Method)
I/flutter (32042): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
I/flutter (32042): at com.android.inte
I/flutter (32042): the response is: null code: error
Thanks a lot for every little help.

Re: MapBox package Flutter: How should we wait/know if "onStyleLoadedCallback" is finished when initialising the map?

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)
Please note: you should only add annotations (e.g. symbols or circles) after onStyleLoadedCallback has been called. So you should add symbols inside onStyleLoadedCallback callback.
Maybe is later but I just wanna post answer because there are some few answers about it ...
Like Edwin TriviƱos says, you just need to set your callback on MapBox parameters and create a new function to do whatever you wanna do. For example, in my case:
Mapbox config:
return MapboxMap(
accessToken: MapboxVariables.accessToken,
styleString: "mapbox://styles/your-url-from-mapbox",
onMapCreated: _onMapCreated,
onStyleLoadedCallback: _onStyleLoaded,
zoomGesturesEnabled: true,
myLocationEnabled: true,
trackCameraPosition: true,
myLocationTrackingMode: MyLocationTrackingMode.Tracking,
onUserLocationUpdated: (UserLocation userLocation){
_movingCameraToLocation();
},
initialCameraPosition: const CameraPosition(
target: LatLng(-33.852, 151.211),
zoom: 11.0,
),
);
As you can see, I'm calling onStyleLoadedCallback: _onStyleLoaded, as a callback. An after that just need a basic _onStyleLoaded function, like this:
void _onStyleLoaded() async {
//your code
}