mapbox-maps-flutter
mapbox-maps-flutter copied to clipboard
PlatformException(recreating_view, trying to create an already created view, view id: '0', null)
Mapbox version:
mapbox_maps_flutter: ^2.6.0
Flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.0, on macOS 15.3.1 24D70 darwin-arm64)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.97.2)
[✓] Connected device (5 available)
[✓] Network resources
Example code:
MapWidget(
key: const ValueKey('mapWidget'),
mapOptions: MapOptions(
pixelRatio: responsive.pixelRatio,
size: Size(
height: responsive.height,
width: responsive.width,
),
),
cameraOptions: CameraOptions(
pitch: 30,
zoom: 16,
center: Point(
coordinates: Position(
-0.1276,
51.5072,
),
),
),
styleUri: ForestEnv().mapboxStyleUri,
onMapCreated: (controller) async {
xxx code xxxx
}.
);
Error logs
lutter: ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
flutter: The following PlatformException was thrown:
flutter: PlatformException(recreating_view, trying to create an already created view, view id: '0', null)
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:646:7)
flutter: #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
[sentry.platformError] [error] Uncaught Platform Error
[sentry.platformError] PlatformException (PlatformException(recreating_view, trying to create an already created view, view id: '0', null))
[sentry.platformError] #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:646:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
platform_channel.dart:334
<asynchronous suspension>
#2 PlatformViewsService.initUiKitView (package:flutter/src/services/platform_views.dart:248:5)
platform_views.dart:248
<asynchronous suspension>
#3 _DarwinViewState._createNewUiKitView (package:flutter/src/widgets/platform_view.dart:921:36)
platform_view.dart:921
<asynchronous suspension>
flutter: <asynchronous suspension>
flutter: #2 PlatformViewsService.initUiKitView (package:flutter/src/services/platform_views.dart:248:5)
flutter: <asynchronous suspension>
flutter: #3 _DarwinViewState._createNewUiKitView (package:flutter/src/widgets/platform_view.dart:921:36)
flutter: <asynchronous suspension>
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
Evidence
https://github.com/user-attachments/assets/7bd9259a-6002-4b9a-be1d-ac948755093c
This is happening on android and iOS devices.
I think I had the same issue once and fixed it by defining a global UniqueKey (outside the widget class) and then using this instead of the ValueKey. Just works of course if you only have a single map view in your app (and not e.g. multiple ones also in other pages).