From 197b367da031c763747605a320dc689284bb8865 Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Fri, 1 Sep 2023 16:31:47 +0100 Subject: [PATCH 1/2] Removed `MoveAndRotateResult` in favour of a `Record` --- lib/flutter_map.dart | 1 - lib/src/map/internal_controller.dart | 25 ++++++++++++------------ lib/src/map/map_controller.dart | 13 ++++++------ lib/src/map/map_controller_impl.dart | 5 ++--- lib/src/misc/move_and_rotate_result.dart | 9 --------- 5 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 lib/src/misc/move_and_rotate_result.dart diff --git a/lib/flutter_map.dart b/lib/flutter_map.dart index a37757612..b2ac1c246 100644 --- a/lib/flutter_map.dart +++ b/lib/flutter_map.dart @@ -34,7 +34,6 @@ export 'package:flutter_map/src/map/options.dart'; export 'package:flutter_map/src/map/widget.dart'; export 'package:flutter_map/src/misc/center_zoom.dart'; export 'package:flutter_map/src/misc/fit_bounds_options.dart'; -export 'package:flutter_map/src/misc/move_and_rotate_result.dart'; export 'package:flutter_map/src/misc/point_extensions.dart'; export 'package:flutter_map/src/misc/position.dart'; export 'package:flutter_map/src/misc/private/positioned_tap_detector_2.dart'; diff --git a/lib/src/map/internal_controller.dart b/lib/src/map/internal_controller.dart index e97e54503..f56314f8a 100644 --- a/lib/src/map/internal_controller.dart +++ b/lib/src/map/internal_controller.dart @@ -140,7 +140,7 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> { /// Note: All named parameters are required to prevent inconsistent default /// values since this method can be called by MapController which declares /// defaults. - MoveAndRotateResult rotateAroundPoint( + ({bool moveSuccess, bool rotateSuccess}) rotateAroundPoint( double degree, { required Point? point, required Offset? offset, @@ -156,13 +156,13 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> { } if (degree == camera.rotation) { - return const MoveAndRotateResult(false, false); + return const (moveSuccess: false, rotateSuccess: false); } if (offset == Offset.zero) { - return MoveAndRotateResult( - true, - rotate( + return ( + moveSuccess: true, + rotateSuccess: rotate( degree, hasGesture: hasGesture, source: source, @@ -178,8 +178,8 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> { : Point(offset!.dx, offset.dy)) .rotate(camera.rotationRad); - return MoveAndRotateResult( - move( + return ( + moveSuccess: move( camera.unproject( rotationCenter + (camera.project(camera.center) - rotationCenter) @@ -191,7 +191,7 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> { source: source, id: id, ), - rotate( + rotateSuccess: rotate( camera.rotation + rotationDiff, hasGesture: hasGesture, source: source, @@ -203,7 +203,7 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> { /// Note: All named parameters are required to prevent inconsistent default /// values since this method can be called by MapController which declares /// defaults. - MoveAndRotateResult moveAndRotate( + ({bool moveSuccess, bool rotateSuccess}) moveAndRotate( LatLng newCenter, double newZoom, double newRotation, { @@ -212,8 +212,8 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> { required MapEventSource source, required String? id, }) => - MoveAndRotateResult( - move( + ( + moveSuccess: move( newCenter, newZoom, offset: offset, @@ -221,7 +221,8 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> { source: source, id: id, ), - rotate(newRotation, id: id, source: source, hasGesture: hasGesture), + rotateSuccess: + rotate(newRotation, id: id, source: source, hasGesture: hasGesture), ); /// Note: All named parameters are required to prevent inconsistent default diff --git a/lib/src/map/map_controller.dart b/lib/src/map/map_controller.dart index c5a6523a9..918bd1e2e 100644 --- a/lib/src/map/map_controller.dart +++ b/lib/src/map/map_controller.dart @@ -10,7 +10,6 @@ import 'package:flutter_map/src/map/inherited_model.dart'; import 'package:flutter_map/src/map/map_controller_impl.dart'; import 'package:flutter_map/src/misc/center_zoom.dart'; import 'package:flutter_map/src/misc/fit_bounds_options.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 @@ -109,9 +108,9 @@ abstract class MapController { /// The emitted [MapEventRotate.source]/[MapEventMove.source] properties will /// be [MapEventSource.mapController]. /// - /// The operation was successful if [MoveAndRotateResult.moveSuccess] and - /// [MoveAndRotateResult.rotateSuccess] are `true`. - MoveAndRotateResult rotateAroundPoint( + /// The operation was successful if both fields of the resulting record are + /// `true`. + ({bool moveSuccess, bool rotateSuccess}) rotateAroundPoint( double degree, { Point? point, Offset? offset, @@ -125,9 +124,9 @@ abstract class MapController { /// /// See documentation on those methods for more details. /// - /// The operation was successful if [MoveAndRotateResult.moveSuccess] and - /// [MoveAndRotateResult.rotateSuccess] are `true`. - MoveAndRotateResult moveAndRotate( + /// The operation was successful if both fields of the resulting record are + /// `true`. + ({bool moveSuccess, bool rotateSuccess}) moveAndRotate( LatLng center, double zoom, double degree, { diff --git a/lib/src/map/map_controller_impl.dart b/lib/src/map/map_controller_impl.dart index 5f6501943..5f610648b 100644 --- a/lib/src/map/map_controller_impl.dart +++ b/lib/src/map/map_controller_impl.dart @@ -10,7 +10,6 @@ import 'package:flutter_map/src/map/internal_controller.dart'; import 'package:flutter_map/src/map/map_controller.dart'; import 'package:flutter_map/src/misc/center_zoom.dart'; import 'package:flutter_map/src/misc/fit_bounds_options.dart'; -import 'package:flutter_map/src/misc/move_and_rotate_result.dart'; import 'package:flutter_map/src/misc/point_extensions.dart'; import 'package:latlong2/latlong.dart'; @@ -57,7 +56,7 @@ class MapControllerImpl implements MapController { ); @override - MoveAndRotateResult rotateAroundPoint( + ({bool moveSuccess, bool rotateSuccess}) rotateAroundPoint( double degree, { Point? point, Offset? offset, @@ -73,7 +72,7 @@ class MapControllerImpl implements MapController { ); @override - MoveAndRotateResult moveAndRotate( + ({bool moveSuccess, bool rotateSuccess}) moveAndRotate( LatLng center, double zoom, double degree, { diff --git a/lib/src/misc/move_and_rotate_result.dart b/lib/src/misc/move_and_rotate_result.dart deleted file mode 100644 index b3431e287..000000000 --- a/lib/src/misc/move_and_rotate_result.dart +++ /dev/null @@ -1,9 +0,0 @@ -import 'package:meta/meta.dart'; - -@immutable -class MoveAndRotateResult { - final bool moveSuccess; - final bool rotateSuccess; - - const MoveAndRotateResult(this.moveSuccess, this.rotateSuccess); -} From 62bcb083858dd465f2ef11156a5814d6b3ba4690 Mon Sep 17 00:00:00 2001 From: JaffaKetchup Date: Sun, 3 Sep 2023 14:23:42 +0100 Subject: [PATCH 2/2] Used `typedef` --- lib/flutter_map.dart | 1 + lib/src/map/internal_controller.dart | 4 ++-- lib/src/map/map_controller.dart | 5 +++-- lib/src/map/map_controller_impl.dart | 5 +++-- lib/src/misc/move_and_rotate_result.dart | 1 + 5 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 lib/src/misc/move_and_rotate_result.dart diff --git a/lib/flutter_map.dart b/lib/flutter_map.dart index b2ac1c246..a37757612 100644 --- a/lib/flutter_map.dart +++ b/lib/flutter_map.dart @@ -34,6 +34,7 @@ export 'package:flutter_map/src/map/options.dart'; export 'package:flutter_map/src/map/widget.dart'; export 'package:flutter_map/src/misc/center_zoom.dart'; export 'package:flutter_map/src/misc/fit_bounds_options.dart'; +export 'package:flutter_map/src/misc/move_and_rotate_result.dart'; export 'package:flutter_map/src/misc/point_extensions.dart'; export 'package:flutter_map/src/misc/position.dart'; export 'package:flutter_map/src/misc/private/positioned_tap_detector_2.dart'; diff --git a/lib/src/map/internal_controller.dart b/lib/src/map/internal_controller.dart index f56314f8a..053842a01 100644 --- a/lib/src/map/internal_controller.dart +++ b/lib/src/map/internal_controller.dart @@ -140,7 +140,7 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> { /// Note: All named parameters are required to prevent inconsistent default /// values since this method can be called by MapController which declares /// defaults. - ({bool moveSuccess, bool rotateSuccess}) rotateAroundPoint( + MoveAndRotateResult rotateAroundPoint( double degree, { required Point? point, required Offset? offset, @@ -203,7 +203,7 @@ class FlutterMapInternalController extends ValueNotifier<_InternalState> { /// Note: All named parameters are required to prevent inconsistent default /// values since this method can be called by MapController which declares /// defaults. - ({bool moveSuccess, bool rotateSuccess}) moveAndRotate( + MoveAndRotateResult moveAndRotate( LatLng newCenter, double newZoom, double newRotation, { diff --git a/lib/src/map/map_controller.dart b/lib/src/map/map_controller.dart index 918bd1e2e..e16c2289f 100644 --- a/lib/src/map/map_controller.dart +++ b/lib/src/map/map_controller.dart @@ -10,6 +10,7 @@ import 'package:flutter_map/src/map/inherited_model.dart'; import 'package:flutter_map/src/map/map_controller_impl.dart'; import 'package:flutter_map/src/misc/center_zoom.dart'; import 'package:flutter_map/src/misc/fit_bounds_options.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 @@ -110,7 +111,7 @@ abstract class MapController { /// /// The operation was successful if both fields of the resulting record are /// `true`. - ({bool moveSuccess, bool rotateSuccess}) rotateAroundPoint( + MoveAndRotateResult rotateAroundPoint( double degree, { Point? point, Offset? offset, @@ -126,7 +127,7 @@ abstract class MapController { /// /// The operation was successful if both fields of the resulting record are /// `true`. - ({bool moveSuccess, bool rotateSuccess}) moveAndRotate( + MoveAndRotateResult moveAndRotate( LatLng center, double zoom, double degree, { diff --git a/lib/src/map/map_controller_impl.dart b/lib/src/map/map_controller_impl.dart index 5f610648b..5f6501943 100644 --- a/lib/src/map/map_controller_impl.dart +++ b/lib/src/map/map_controller_impl.dart @@ -10,6 +10,7 @@ import 'package:flutter_map/src/map/internal_controller.dart'; import 'package:flutter_map/src/map/map_controller.dart'; import 'package:flutter_map/src/misc/center_zoom.dart'; import 'package:flutter_map/src/misc/fit_bounds_options.dart'; +import 'package:flutter_map/src/misc/move_and_rotate_result.dart'; import 'package:flutter_map/src/misc/point_extensions.dart'; import 'package:latlong2/latlong.dart'; @@ -56,7 +57,7 @@ class MapControllerImpl implements MapController { ); @override - ({bool moveSuccess, bool rotateSuccess}) rotateAroundPoint( + MoveAndRotateResult rotateAroundPoint( double degree, { Point? point, Offset? offset, @@ -72,7 +73,7 @@ class MapControllerImpl implements MapController { ); @override - ({bool moveSuccess, bool rotateSuccess}) moveAndRotate( + MoveAndRotateResult moveAndRotate( LatLng center, double zoom, double degree, { diff --git a/lib/src/misc/move_and_rotate_result.dart b/lib/src/misc/move_and_rotate_result.dart new file mode 100644 index 000000000..b6887349f --- /dev/null +++ b/lib/src/misc/move_and_rotate_result.dart @@ -0,0 +1 @@ +typedef MoveAndRotateResult = ({bool moveSuccess, bool rotateSuccess});