Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: merge MapInternalController with MapControllerImpl #1738

Merged
merged 7 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/flutter_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export 'package:flutter_map/src/layer/tile_layer/tile_update_transformer.dart';
export 'package:flutter_map/src/map/camera/camera.dart';
export 'package:flutter_map/src/map/camera/camera_constraint.dart';
export 'package:flutter_map/src/map/camera/camera_fit.dart';
export 'package:flutter_map/src/map/controller/impl.dart';
export 'package:flutter_map/src/map/controller/map_controller.dart';
export 'package:flutter_map/src/map/controller/map_controller_impl.dart';
export 'package:flutter_map/src/map/options/cursor_keyboard_rotation.dart';
export 'package:flutter_map/src/map/options/interaction.dart';
export 'package:flutter_map/src/map/options/options.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@ import 'dart:math' as math;
import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_map/src/gestures/interactive_flag.dart';
import 'package:flutter_map/src/gestures/latlng_tween.dart';
import 'package:flutter_map/src/gestures/map_events.dart';
import 'package:flutter_map/src/gestures/multi_finger_gesture.dart';
import 'package:flutter_map/src/gestures/positioned_tap_detector_2.dart';
import 'package:flutter_map/src/map/camera/camera.dart';
import 'package:flutter_map/src/map/controller/internal.dart';
import 'package:flutter_map/src/map/options/cursor_keyboard_rotation.dart';
import 'package:flutter_map/src/map/options/interaction.dart';
import 'package:flutter_map/src/map/options/options.dart';
import 'package:flutter_map/src/misc/point_extensions.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:vector_math/vector_math_64.dart';

Expand All @@ -26,23 +16,22 @@ typedef InteractiveViewerBuilder = Widget Function(

/// Applies interactions (gestures/scroll/taps etc) to the current [MapCamera]
/// via the internal [controller].
class FlutterMapInteractiveViewer extends StatefulWidget {
class MapInteractiveViewer extends StatefulWidget {
final InteractiveViewerBuilder builder;
final FlutterMapInternalController controller;
final MapControllerImpl controller;

const FlutterMapInteractiveViewer({
const MapInteractiveViewer({
super.key,
required this.builder,
required this.controller,
});

@override
State<FlutterMapInteractiveViewer> createState() =>
FlutterMapInteractiveViewerState();
State<MapInteractiveViewer> createState() => MapInteractiveViewerState();
}

class FlutterMapInteractiveViewerState
extends State<FlutterMapInteractiveViewer> with TickerProviderStateMixin {
class MapInteractiveViewerState extends State<MapInteractiveViewer>
with TickerProviderStateMixin {
static const int _kMinFlingVelocity = 800;
static const _kDoubleTapZoomDuration = 200;
static const doubleTapDelay = Duration(milliseconds: 250);
Expand Down Expand Up @@ -336,11 +325,10 @@ class FlutterMapInteractiveViewerState
if (_interactionOptions.cursorKeyboardRotationOptions.setNorthOnClick &&
_ckrTriggered.value &&
_ckrInitialDegrees == _camera.rotation) {
widget.controller.rotate(
widget.controller.rotateRaw(
getCursorRotationDegrees(event.localPosition),
hasGesture: true,
source: MapEventSource.cursorKeyboardRotation,
id: null,
);
}

Expand Down Expand Up @@ -372,14 +360,13 @@ class FlutterMapInteractiveViewerState
final baseSetNorth =
getCursorRotationDegrees(event.localPosition) - _ckrClickDegrees;

widget.controller.rotate(
widget.controller.rotateRaw(
_interactionOptions.cursorKeyboardRotationOptions.behaviour ==
CursorRotationBehaviour.setNorth
? baseSetNorth
: (_ckrInitialDegrees + baseSetNorth) % 360,
hasGesture: true,
source: MapEventSource.cursorKeyboardRotation,
id: null,
);

if (_interactionOptions.cursorKeyboardRotationOptions.behaviour ==
Expand Down Expand Up @@ -408,13 +395,11 @@ class FlutterMapInteractiveViewerState
pointerSignal.localPosition.toPoint(),
newZoom,
);
widget.controller.move(
widget.controller.moveRaw(
newCenter,
newZoom,
offset: Offset.zero,
hasGesture: true,
source: MapEventSource.scrollWheel,
id: null,
);
},
);
Expand Down Expand Up @@ -619,13 +604,11 @@ class FlutterMapInteractiveViewerState
}

if (_pinchZoomStarted || _pinchMoveStarted) {
widget.controller.move(
widget.controller.moveRaw(
newCenter,
newZoom,
offset: Offset.zero,
hasGesture: true,
source: MapEventSource.onMultiFinger,
id: null,
);
}
}
Expand Down Expand Up @@ -664,14 +647,13 @@ class FlutterMapInteractiveViewerState
final rotatedVector = vector.rotate(degrees2Radians * rotationDiff);
final newCenter = rotationCenter + rotatedVector;

widget.controller.moveAndRotate(
widget.controller.moveAndRotateRaw(
_camera.unproject(newCenter),
_camera.zoom,
_camera.rotation + rotationDiff,
offset: Offset.zero,
hasGesture: true,
source: MapEventSource.onMultiFinger,
id: null,
);
}
}
Expand Down Expand Up @@ -844,13 +826,11 @@ class FlutterMapInteractiveViewerState
}

void _handleDoubleTapZoomAnimation() {
widget.controller.move(
widget.controller.moveRaw(
_doubleTapCenterAnimation.value,
_doubleTapZoomAnimation.value,
offset: Offset.zero,
hasGesture: true,
source: MapEventSource.doubleTapZoomAnimationController,
id: null,
);
}

Expand All @@ -874,13 +854,11 @@ class FlutterMapInteractiveViewerState
final max = _options.maxZoom ?? double.infinity;
final actualZoom = math.max(min, math.min(max, newZoom));

widget.controller.move(
widget.controller.moveRaw(
_camera.center,
actualZoom,
offset: Offset.zero,
hasGesture: true,
source: MapEventSource.doubleTapHold,
id: null,
);
}
}
Expand All @@ -896,13 +874,11 @@ class FlutterMapInteractiveViewerState
_flingAnimation.value.toPoint().rotate(_camera.rotationRad);
final newCenter = _camera.unproject(newCenterPoint);

widget.controller.move(
widget.controller.moveRaw(
newCenter,
_camera.zoom,
offset: Offset.zero,
hasGesture: true,
source: MapEventSource.flingAnimationController,
id: null,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import 'package:http/http.dart';
/// Note that specifying a [fallbackUrl] will prevent this image provider from
/// being cached.
@immutable
class FlutterMapNetworkImageProvider
extends ImageProvider<FlutterMapNetworkImageProvider> {
class MapNetworkImageProvider extends ImageProvider<MapNetworkImageProvider> {
JaffaKetchup marked this conversation as resolved.
Show resolved Hide resolved
/// The URL to fetch the tile from (GET request)
final String url;

Expand Down Expand Up @@ -56,7 +55,7 @@ class FlutterMapNetworkImageProvider
/// Supports falling back to a secondary URL, if the primary URL fetch fails.
/// Note that specifying a [fallbackUrl] will prevent this image provider from
/// being cached.
const FlutterMapNetworkImageProvider({
const MapNetworkImageProvider({
required this.url,
required this.fallbackUrl,
required this.headers,
Expand All @@ -68,7 +67,7 @@ class FlutterMapNetworkImageProvider

@override
ImageStreamCompleter loadImage(
FlutterMapNetworkImageProvider key,
MapNetworkImageProvider key,
ImageDecoderCallback decode,
) =>
MultiFrameImageStreamCompleter(
Expand All @@ -83,7 +82,7 @@ class FlutterMapNetworkImageProvider
);

Future<Codec> _load(
FlutterMapNetworkImageProvider key,
MapNetworkImageProvider key,
ImageDecoderCallback decode, {
bool useFallback = false,
}) {
Expand All @@ -109,15 +108,15 @@ class FlutterMapNetworkImageProvider
}

@override
SynchronousFuture<FlutterMapNetworkImageProvider> obtainKey(
SynchronousFuture<MapNetworkImageProvider> obtainKey(
ImageConfiguration configuration,
) =>
SynchronousFuture(this);

@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is FlutterMapNetworkImageProvider &&
(other is MapNetworkImageProvider &&
fallbackUrl == null &&
url == other.url);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class NetworkTileProvider extends TileProvider {

@override
ImageProvider getImage(TileCoordinates coordinates, TileLayer options) =>
FlutterMapNetworkImageProvider(
MapNetworkImageProvider(
url: getTileUrl(coordinates, options),
fallbackUrl: getTileFallbackUrl(coordinates, options),
headers: headers,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/map/camera/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MapCamera {
/// The camera of the closest [FlutterMap] ancestor. If this is called from a
/// context with no [FlutterMap] ancestor null, is returned.
static MapCamera? maybeOf(BuildContext context) =>
FlutterMapInheritedModel.maybeCameraOf(context);
MapInheritedModel.maybeCameraOf(context);

/// The camera of the closest [FlutterMap] ancestor. If this is called from a
/// context with no [FlutterMap] ancestor a [StateError] will be thrown.
Expand Down
101 changes: 0 additions & 101 deletions lib/src/map/controller/impl.dart

This file was deleted.

9 changes: 2 additions & 7 deletions lib/src/map/controller/map_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_map/src/gestures/map_events.dart';
import 'package:flutter_map/src/map/camera/camera.dart';
import 'package:flutter_map/src/map/camera/camera_fit.dart';
import 'package:flutter_map/src/map/controller/impl.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/src/map/inherited_model.dart';
import 'package:flutter_map/src/map/widget.dart';
import 'package:flutter_map/src/misc/move_and_rotate_result.dart';
import 'package:latlong2/latlong.dart';

/// Controller to programmatically interact with [FlutterMap], such as
Expand All @@ -31,7 +26,7 @@ abstract class MapController {
/// from a context with no [FlutterMap] ancestor a [StateError] will be
/// thrown.
static MapController? maybeOf(BuildContext context) =>
FlutterMapInheritedModel.maybeControllerOf(context);
MapInheritedModel.maybeControllerOf(context);

/// The controller for the closest [FlutterMap] ancestor. If this is called
/// from a context with no [FlutterMap] ancestor a [StateError] will be
Expand Down
Loading
Loading