mapbox / mapbox/mapbox-maps-flutter
Android: setStyleJSON not working after upgrading plugin version 2+
Nessuno ha ancora preso questa issue.
- Lingua principale
- Dart
- Stelle
- 380
- Fork
- 204
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
After upgrading the plugin from version 1.1.0 to 2.0.0, I have some issues when developing for Android.
I try to set a custom style json like this in the onMapCreated callback:
_onMapCreated(MapboxMap mapboxMap) async {
this.mapboxMap = mapboxMap;
final styleJson = await rootBundle.loadString("assets/map-styles/my_style.json");
mapboxMap.style.setStyleJSON(styleJson);
print("done");
}
I see the log message in the console, so the code is executed as expected without any error, but I still see the default Mapbox style on Android. It is working as expected on iOS and it was also working on Android using plugin version 1.1.0.
Futhermore, when adding a layer in the onStyleLoadedListener like this:
_onMapStyleLoaded(StyleLoadedEventData styleLoadedEventData) async {
final linesData = await rootBundle.loadString('assets/map-data/lines.json');
await mapboxMap?.style.addSource(GeoJsonSource(id: "source_lines", data: linesData));
await mapboxMap?.style.addLayer(
LineLayer(
id: "layer_lines",
sourceId: "source_lines"
)
);
}
I see the added layer, but I also see an exception on Android:
E/flutter (22160): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Throwable, java.lang.Throwable: Source source_lines already exists, Cause: null, Stacktrace: java.lang.Throwable: Source source_lines already exists
E/flutter (22160): at com.mapbox.maps.mapbox_maps.StyleController.addStyleSource(StyleController.kt:288)
E/flutter (22160): at com.mapbox.maps.mapbox_maps.pigeons.StyleManager$Companion.setUp$lambda-51$lambda-50(MapInterfaces.kt:5972)
E/flutter (22160): at com.mapbox.maps.mapbox_maps.pigeons.StyleManager$Companion.$r8$lambda$DXAQ35E-7m0eWhGSNgtBkwfDJqQ(Unknown Source:0)
E/flutter (22160): at com.mapbox.maps.mapbox_maps.pigeons.StyleManager$Companion$$ExternalSyntheticLambda8.onMessage(Unknown Source:2)
E/flutter (22160): at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:261)
E/flutter (22160): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/flutter (22160): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (22160): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (22160): at android.os.Handler.handleCallback(Handler.java:958)
E/flutter (22160): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (22160): at android.os.Looper.loopOnce(Looper.java:205)
E/flutter (22160): at android.os.Looper.loop(Looper.java:294)
E/flutter (22160): at android.app.ActivityThread.main(ActivityThread.java:8177)
E/flutter (22160): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (22160): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/flutter (22160): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
E/flutter (22160): , null)
E/flutter (22160): #0 StyleManager.addStyleSource (package:mapbox_maps_flutter/src/pigeons/map_interfaces.dart:5816:7)
E/flutter (22160):
E/flutter (22160): #1 StyleSource.addSource. (package:mapbox_maps_flutter/src/style/style.dart:317:66)
E/flutter (22160):
E/flutter (22160): #2 MapPageState._onMapStyleLoaded (package:flutter_mapbox/main.dart:48:5)
E/flutter (22160):
It is working as expected on iOS and it was also working on Android with plugin 1.1.0.
Full sample project:
flutter_mapbox.zip
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo su Android l'esempio flutter_mapbox collegato e confrontando il comportamento tra le versioni del plugin 1.1.0 e 2.0.0. Esamina il percorso Android StyleController.addStyleSource identificato nello stack trace e i callback setStyleJSON/style-loaded. Il lavoro è completato quando viene visualizzato lo stile personalizzato e la source può essere aggiunta senza la duplicate-source exception.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- android, dart, flutter
- Ambito
- mobile-dev
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100