Unable to establish connection on channel
Hello Mapbox team.
Since upgrading from mapbox_maps_flutter v1.1.0 to v2.8.0 we have been getting heaps of "Unable to establish connection on channel" errors in production which is taking up our Sentry quota. (As part of this upgrade I also went from flutter v3.22.0 to v3.29.0 so maybe this could have contributed?)
Here are examples of these types of errors we are seeing:
PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.mapbox_maps_flutter._PointAnnotationMessenger.setTextIgnorePlacement.0"., null, null)
PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.mapbox_maps_flutter._PointAnnotationMessenger.setTextOptional.0"., null, null)
PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.mapbox_maps_flutter._PointAnnotationMessenger.setIconIgnorePlacement.0"., null, null)
PlatformException(channel-error, Unable to establish connection on channel: "dev.flutter.pigeon.mapbox_maps_flutter._PointAnnotationMessenger.setSymbolZOrder.0"., null, null)
This is happening on a range of devices and operating systems (both android and ios)
Looks like there is a similar issue that got raised 3 days before this one https://github.com/mapbox/mapbox-maps-flutter/issues/976
Any ideas on what is going wrong?
I have also been still getting a number of complaints from customers about either their map not loading at all or just freezing. It feels like it might be something related to this issue?
Don't have details on this device other than its android
Using android 10, HUAWEI CLT-L09
Using Android 10, HUAWEI VOG-L29 No screenshot but basically the app loads for a few seconds and then freezes
Would really love some explanations and solutions to this! Our app is unusable to those people above. May have to downgrade back to v1.1.0 but don't really want to do that as there are other issues with that version!
Thanks in advance team. Really love using mapbox 😊
Hi, I believe the issue #976 you're referring to is due to the operating system he is using. It would be helpful to include some code snippets demonstrating how you're utilizing the PointAnnotationManager.
This is how we use it in _onMapCreated
_onMapCreated(MapboxMap mapboxMap) async {
this.mapboxMap = mapboxMap;
GeocodeService.instance.setMapboxMap(mapboxMap, key: 'main');
mapboxMap.compass.updateSettings(CompassSettings(enabled: false));
mapboxMap.scaleBar.updateSettings(ScaleBarSettings(enabled: false));
mapboxMap.gestures.updateSettings(GesturesSettings(
pitchEnabled: false,
));
pointAnnotationManager = await mapboxMap.annotations
.createPointAnnotationManager(
below: 'settlement-minor-label', id: 'pin-layer');
pointAnnotationManager
.addOnPointAnnotationClickListener(AnnotationClickListener(this));
// This just won't show if you don't have location enabled
await mapboxMap.location.updateSettings(LocationComponentSettings(
enabled: widget.includeUserLocation,
pulsingEnabled: true,
));
mapboxMap.setOnMapMoveListener((coordinate) async {
if (_animationController.isCompleted) {
_animationController.reverse();
}
});
mapboxMap.setOnMapTapListener((coordinate) async {
await Future.delayed(const Duration(milliseconds: 50));
if (!selectionHappening && selectedProduct != null) {
deselectPin();
}
});
// uncomment for testing
// mapboxMap
// .setDebug([MapDebugOptions(data: MapDebugOptionsData.COLLISION)], true);
final canShowUserLocation = await checkCanShowUserLocation();
await pointAnnotationManager.setTextAllowOverlap(false);
await pointAnnotationManager.setTextIgnorePlacement(false);
await pointAnnotationManager.setIconIgnorePlacement(false);
await loadPinAssets();
await addLocations(widget.mapPin);
flyToRegion();
if (widget.flyToPinsOnMapLoad) {
flyToPins();
}
if (widget.includeUserLocation && widget.flyToUserLocationOnMapLoad) {
// uncomment for testing
// final canShowUserLocation = false;
final selectedCountry =
BlocProvider.of<SelectedCountryBloc>(context).state.selectedCountry;
if (canShowUserLocation &&
widget.filterState?.regionsNISelected.isEmpty == true) {
await flyToUserLocation(onlyFlyIfInSelectedCountry: true);
}
}
}
And then onCameraChangeListener:
void _onCameraChangeListener(CameraChangedEventData change) async {
final cameraState = await mapboxMap.getCameraState();
await pointAnnotationManager.setTextAllowOverlap(false);
await pointAnnotationManager.setTextIgnorePlacement(false);
await pointAnnotationManager.setIconIgnorePlacement(false);
isZoomedIn = cameraState.zoom > 9.5;
// We don't want the pins to be covered by the city names when zoomed in
mapboxMap.style.moveStyleLayer(
'pin-layer',
isZoomedIn
? LayerPosition()
: LayerPosition(below: 'settlement-minor-label'));
pointAnnotationManager.setIconAllowOverlap(true);
pointAnnotationManager.setTextOptional(true);
pointAnnotationManager.setSymbolZOrder(SymbolZOrder.VIEWPORT_Y);
}
BTW the reason we have it being called in the camera change listener is because we were having issues with it applying consistently in onMapCreated
Sorry, I tried your code but couldn't reproduce the issue on my test devices. The code looks fine to me.
Did you call this method?
void main() {
WidgetsFlutterBinding.ensureInitialized();
...
runApp(MaterialApp(home: MapsDemo()));
}
By the way, you should consider using mapboxMap.setOnMapZoomListener(...) instead. The CameraChangeListener will also trigger when the map is moved, not just zoomed. Also, if you're working with a large number of pins, consider using a SymbolLayer instead of PointAnnotations for better performance.
Thanks @tchengck
Ok I was able to reproduce the issue on a Huawei device. I was able to fix the issue by setting androidHostingMode: AndroidPlatformViewHostingMode.HC,
Thanks @tchengck
Ok I was able to reproduce the issue on a Huawei device. I was able to fix the issue by setting
androidHostingMode: AndroidPlatformViewHostingMode.HC,
do you have some more details to this? I am having same issue whilte setting the token at app initialization