Skip to content

Commit

Permalink
Revert "Fix flutter 3.x crashes (flutter-mapbox-gl#1293)"
Browse files Browse the repository at this point in the history
This reverts commit 9eef30d.
  • Loading branch information
FreeGrow committed Sep 21, 2023
1 parent 5d6c19d commit 3b499c9
Show file tree
Hide file tree
Showing 6 changed files with 388 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1554,14 +1554,12 @@ private void destroyMapViewIfNecessary() {
return;
}

mapView.onStop();
mapView.onDestroy();

if (locationComponent != null) {
locationComponent.setLocationComponentEnabled(false);
}
stopListeningForLocationUpdates();

mapView.onDestroy();
mapView = null;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/src/mapbox_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ class MapboxMap extends StatefulWidget {
/// * All fade/transition animations have completed
final OnMapIdleCallback? onMapIdle;

// This flag has no effect anymore and will be removed in the next major release.
@deprecated
/// Use delayed disposal of Android View Controller to avoid flutter 3.x.x crashes
/// Use with caution - this is not yet production ready since several users still report crashes after using this workaround
final bool? useDelayedDisposal;

/// Override hybrid mode per map instance
Expand Down Expand Up @@ -261,6 +261,7 @@ class _MapboxMapState extends State<MapboxMap> {
'accessToken': widget.accessToken,
'onAttributionClickOverride': widget.onAttributionClick != null,
'dragEnabled': widget.dragEnabled,
'useDelayedDisposal': widget.useDelayedDisposal,
'useHybridCompositionOverride': widget.useHybridCompositionOverride,
};
return _mapboxGlPlatform.buildView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';

part 'src/view_wrappers.dart';
part 'src/annotation.dart';
part 'src/callbacks.dart';
part 'src/camera.dart';
Expand Down
38 changes: 30 additions & 8 deletions mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class MethodChannelMapboxGl extends MapboxGlPlatform {
OnPlatformViewCreatedCallback onPlatformViewCreated,
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers) {
if (defaultTargetPlatform == TargetPlatform.android) {
final useDelayedDisposalParam =
(creationParams['useDelayedDisposal'] ?? false) as bool;
final useHybridCompositionParam =
(creationParams['useHybridCompositionOverride'] ??
useHybridComposition) as bool;
Expand All @@ -160,14 +162,25 @@ class MethodChannelMapboxGl extends MapboxGlPlatform {
},
onCreatePlatformView: (PlatformViewCreationParams params) {
late AndroidViewController controller;
controller = PlatformViewsService.initAndroidView(
id: params.id,
viewType: 'plugins.flutter.io/mapbox_gl',
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
onFocus: () => params.onFocusChanged(true),
);
if (useDelayedDisposalParam) {
controller = WrappedPlatformViewsService.initAndroidView(
id: params.id,
viewType: 'plugins.flutter.io/mapbox_gl',
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
onFocus: () => params.onFocusChanged(true),
);
} else {
controller = PlatformViewsService.initAndroidView(
id: params.id,
viewType: 'plugins.flutter.io/mapbox_gl',
layoutDirection: TextDirection.ltr,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
onFocus: () => params.onFocusChanged(true),
);
}
controller.addOnPlatformViewCreatedListener(
params.onPlatformViewCreated,
);
Expand All @@ -180,6 +193,15 @@ class MethodChannelMapboxGl extends MapboxGlPlatform {
},
);
} else {
if (useDelayedDisposalParam) {
return AndroidViewWithWrappedController(
viewType: 'plugins.flutter.io/mapbox_gl',
onPlatformViewCreated: onPlatformViewCreated,
gestureRecognizers: gestureRecognizers,
creationParams: creationParams,
creationParamsCodec: const StandardMessageCodec(),
);
}
return AndroidView(
viewType: 'plugins.flutter.io/mapbox_gl',
onPlatformViewCreated: onPlatformViewCreated,
Expand Down
Loading

0 comments on commit 3b499c9

Please sign in to comment.