Open felixkrautschuk opened 3 months ago
I just noticed that the same PlatformException also occurs on iOS:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(0, Source source_lines already exists, null, null)
0 StyleManager.addStyleSource (package:mapbox_maps_flutter/src/pigeons/map_interfaces.dart:5816:7)
#1 StyleSource.addSource. (package:mapbox_maps_flutter/src/style/style.dart:317:66) #2 MapPageState._onMapStyleLoaded (package:flutter_mapbox/pages/map-page.dart:54:5)
on iOS, the issue does not occur when setting styleUri to an empty string
MapWidget(
//...
styleUri: "",
//...
),
but that does not help on Android
Hey! Any news on this topic? I get the same exact issue when trying to load polyline on Android (no issue on iOS) @felixkrautschuk were you able to find a workaround?
@mabilinab adding a delay works for me on Android
_onMapCreated(MapboxMap mapboxMap) async {
final styleJson = await rootBundle.loadString("assets/map-styles/my_style.json");
Future.delayed(const Duration(milliseconds: 50), () {
mapboxMap.style.setStyleJSON(styleJson);
});
}
However, I don't like this as there is no guarantee that 50ms is always enough.
I was also able to find a workaround: It seems like when you import a custom map URL, you need to use await -- this solved most of the issues for me:
void _onMapCreated(MapboxMap mapboxMap) async {
_mapboxMap = mapboxMap;
//Initialize the map settings
await _mapboxMap!.loadStyleURI("mapbox://styles/XXX/XXXXXX");
}
_onStyleLoadedCallback(StyleLoadedEventData data) async {
//.... rest of your code
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:
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:
I see the added layer, but I also see an exception on Android:
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