Skip to content

Commit

Permalink
Revert "Workaround for disposal crash with flutter3 (flutter-mapbox-g…
Browse files Browse the repository at this point in the history
…l#1172)"

This reverts commit 2ebb7a5.
  • Loading branch information
FreeGrow committed Sep 21, 2023
1 parent c0e7dc6 commit 3dfa372
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 350 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ xml ...

[Recommended](https://docs.mapbox.com/help/tutorials/first-steps-ios-sdk/#display-the-users-location) explanation about "Shows your location on the map and helps improve the map".

## Flutter 3.x.x issues and experimental workarounds
Since Flutter 3.x.x was introduced, it exposed some race conditions resulting in occasional crashes upon map disposal. The parameter `useDelayedDisposal` was introduced as a workaround for this issue until Flutter and/or Mapbox fix this issue properly. Use with caution - this is not yet production ready since several users still report crashes after using this workaround.

## Running the example code
See the [documentation about this topic](doc/RUNNING_EXAMPLE_CODE.md)

Expand Down
1 change: 1 addition & 0 deletions example/lib/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
// ignore: unnecessary_import
import 'dart:typed_data';

import 'package:flutter/material.dart';
Expand Down
1 change: 1 addition & 0 deletions example/lib/place_fill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
// ignore: unnecessary_import
import 'dart:typed_data';

import 'package:flutter/material.dart';
Expand Down
1 change: 1 addition & 0 deletions example/lib/place_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
// ignore: unnecessary_import
import 'dart:typed_data';

import 'package:flutter/material.dart';
Expand Down
1 change: 1 addition & 0 deletions example/lib/place_symbol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'dart:async'; // ignore: unnecessary_import
import 'dart:core';
import 'dart:math';
// ignore: unnecessary_import
import 'dart:typed_data';

import 'package:flutter/material.dart';
Expand Down
13 changes: 1 addition & 12 deletions lib/src/mapbox_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class MapboxMap extends StatefulWidget {
AnnotationType.line,
AnnotationType.circle,
],
this.useDelayedDisposal,
this.useHybridCompositionOverride,
}) : assert(annotationOrder.length <= 4),
assert(annotationConsumeTapEvents.length > 0),
super(key: key);
Expand Down Expand Up @@ -224,13 +222,6 @@ class MapboxMap extends StatefulWidget {
/// * All fade/transition animations have completed
final OnMapIdleCallback? onMapIdle;

/// 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
final bool? useHybridCompositionOverride;

/// Set `MapboxMap.useHybridComposition` to `false` in order use Virtual-Display
/// (better for Android 9 and below but may result in errors on Android 12)
/// or leave it `true` (default) to use Hybrid composition (Slower on Android 9 and below).
Expand Down Expand Up @@ -260,9 +251,7 @@ class _MapboxMapState extends State<MapboxMap> {
'options': _MapboxMapOptions.fromWidget(widget).toMap(),
'accessToken': widget.accessToken,
'onAttributionClickOverride': widget.onAttributionClick != null,
'dragEnabled': widget.dragEnabled,
'useDelayedDisposal': widget.useDelayedDisposal,
'useHybridCompositionOverride': widget.useHybridCompositionOverride,
'dragEnabled': widget.dragEnabled
};
return _mapboxGlPlatform.buildView(
creationParams, onPlatformViewCreated, widget.gestureRecognizers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ 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
45 changes: 10 additions & 35 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,12 +141,7 @@ 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;
if (useHybridCompositionParam) {
if (useHybridComposition) {
return PlatformViewLink(
viewType: 'plugins.flutter.io/mapbox_gl',
surfaceFactory: (
Expand All @@ -161,26 +156,15 @@ class MethodChannelMapboxGl extends MapboxGlPlatform {
);
},
onCreatePlatformView: (PlatformViewCreationParams params) {
late AndroidViewController controller;
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),
);
}
final SurfaceAndroidViewController controller =
PlatformViewsService.initSurfaceAndroidView(
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 @@ -193,15 +177,6 @@ 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 3dfa372

Please sign in to comment.