Skip to content

Commit

Permalink
Tidy up MapEvents
Browse files Browse the repository at this point in the history
 - Remove MapEventSource.initialized since it is no longer used.
 - Make MapEvents const classes.
 - Use super parameters syntax.
  • Loading branch information
rorystephenson committed May 1, 2023
1 parent fa5116a commit 84b0029
Showing 1 changed file with 95 additions and 104 deletions.
199 changes: 95 additions & 104 deletions lib/src/gestures/map_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ enum MapEventSource {
doubleTapZoomAnimationController,
interactiveFlagsChanged,
fitBounds,
initialization,
custom,
scrollWheel,
}
Expand All @@ -28,16 +27,20 @@ enum MapEventSource {
/// is usually related to performed gesture on the map itself or it can
/// be an event related to map configuration
abstract class MapEvent {
/// who / what issued the event
/// Who / what issued the event.
final MapEventSource source;

/// geographical coordinates related to current event
/// Geographical coordinates related to current event.
final LatLng center;

/// zoom value related to current event
/// Zoom value related to current event.
final double zoom;

MapEvent({required this.source, required this.center, required this.zoom});
const MapEvent({
required this.source,
required this.center,
required this.zoom,
});
}

/// Base event class which is emitted by MapController instance and
Expand All @@ -49,187 +52,175 @@ abstract class MapEventWithMove extends MapEvent {
/// Zoom value of point where map is being pointed to
final double targetZoom;

MapEventWithMove({
const MapEventWithMove({
required this.targetCenter,
required this.targetZoom,
required MapEventSource source,
required LatLng center,
required double zoom,
}) : super(source: source, center: center, zoom: zoom);
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when map is tapped
class MapEventTap extends MapEvent {
/// Point coordinates where user has tapped
final LatLng tapPosition;

MapEventTap({
const MapEventTap({
required this.tapPosition,
required MapEventSource source,
required LatLng center,
required double zoom,
}) : super(source: source, center: center, zoom: zoom);
required super.source,
required super.center,
required super.zoom,
});
}

class MapEventSecondaryTap extends MapEvent {
/// Point coordinates where user has tapped
final LatLng tapPosition;

MapEventSecondaryTap({
const MapEventSecondaryTap({
required this.tapPosition,
required MapEventSource source,
required LatLng center,
required double zoom,
}) : super(source: source, center: center, zoom: zoom);
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when map is long-pressed
class MapEventLongPress extends MapEvent {
/// Point coordinates where user has long-pressed
final LatLng tapPosition;

MapEventLongPress({
const MapEventLongPress({
required this.tapPosition,
required MapEventSource source,
required LatLng center,
required double zoom,
}) : super(source: source, center: center, zoom: zoom);
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when map is being dragged
/// Event which is fired when map is being moved.
class MapEventMove extends MapEventWithMove {
/// Custom ID to identify related object(s)
final String? id;

MapEventMove({
const MapEventMove({
this.id,
required LatLng targetCenter,
required double targetZoom,
required MapEventSource source,
required LatLng center,
required double zoom,
required super.source,
required super.center,
required super.zoom,
}) : super(
targetCenter: targetCenter,
targetZoom: targetZoom,
source: source,
center: center,
zoom: zoom,
);
}

/// Event which is fired when dragging is started
class MapEventMoveStart extends MapEvent {
MapEventMoveStart(
{required MapEventSource source,
required LatLng center,
required double zoom})
: super(source: source, center: center, zoom: zoom);
const MapEventMoveStart({
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when dragging is finished
class MapEventMoveEnd extends MapEvent {
MapEventMoveEnd(
{required MapEventSource source,
required LatLng center,
required double zoom})
: super(source: source, center: center, zoom: zoom);
const MapEventMoveEnd({
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when animation started by fling gesture is in progress
class MapEventFlingAnimation extends MapEventWithMove {
MapEventFlingAnimation({
const MapEventFlingAnimation({
required LatLng targetCenter,
required double targetZoom,
required MapEventSource source,
required LatLng center,
required double zoom,
required super.source,
required super.center,
required super.zoom,
}) : super(
targetCenter: targetCenter,
targetZoom: targetZoom,
source: source,
center: center,
zoom: zoom,
);
}

/// Emits when InteractiveFlags contains fling and there wasn't enough velocity
/// to start fling animation
class MapEventFlingAnimationNotStarted extends MapEvent {
MapEventFlingAnimationNotStarted(
{required MapEventSource source,
required LatLng center,
required double zoom})
: super(source: source, center: center, zoom: zoom);
const MapEventFlingAnimationNotStarted({
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when fling gesture is detected
class MapEventFlingAnimationStart extends MapEvent {
MapEventFlingAnimationStart(
{required MapEventSource source,
required LatLng center,
required double zoom})
: super(source: source, center: center, zoom: zoom);
const MapEventFlingAnimationStart({
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when animation started by fling gesture finished
class MapEventFlingAnimationEnd extends MapEvent {
MapEventFlingAnimationEnd(
{required MapEventSource source,
required LatLng center,
required double zoom})
: super(source: source, center: center, zoom: zoom);
const MapEventFlingAnimationEnd({
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when map is double tapped
class MapEventDoubleTapZoom extends MapEventWithMove {
MapEventDoubleTapZoom({
const MapEventDoubleTapZoom({
required LatLng targetCenter,
required double targetZoom,
required MapEventSource source,
required LatLng center,
required double zoom,
required super.source,
required super.center,
required super.zoom,
}) : super(
targetCenter: targetCenter,
targetZoom: targetZoom,
source: source,
center: center,
zoom: zoom,
);
}

/// Event which is fired when scroll wheel is used to zoom
class MapEventScrollWheelZoom extends MapEventWithMove {
MapEventScrollWheelZoom({
const MapEventScrollWheelZoom({
required LatLng targetCenter,
required double targetZoom,
required MapEventSource source,
required LatLng center,
required double zoom,
required super.source,
required super.center,
required super.zoom,
}) : super(
targetCenter: targetCenter,
targetZoom: targetZoom,
source: source,
center: center,
zoom: zoom,
);
}

/// Event which is fired when animation for double tap gesture is started
class MapEventDoubleTapZoomStart extends MapEvent {
MapEventDoubleTapZoomStart(
{required MapEventSource source,
required LatLng center,
required double zoom})
: super(source: source, center: center, zoom: zoom);
const MapEventDoubleTapZoomStart({
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when animation for double tap gesture ends
class MapEventDoubleTapZoomEnd extends MapEvent {
MapEventDoubleTapZoomEnd(
{required MapEventSource source,
required LatLng center,
required double zoom})
: super(source: source, center: center, zoom: zoom);
const MapEventDoubleTapZoomEnd({
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when map is being rotated
Expand All @@ -243,29 +234,29 @@ class MapEventRotate extends MapEvent {
/// Target rotation in radians
final double targetRotation;

MapEventRotate({
const MapEventRotate({
required this.id,
required this.currentRotation,
required this.targetRotation,
required MapEventSource source,
required LatLng center,
required double zoom,
}) : super(source: source, center: center, zoom: zoom);
required super.source,
required super.center,
required super.zoom,
});
}

/// Event which is fired when rotate gesture was started
class MapEventRotateStart extends MapEvent {
MapEventRotateStart(
{required MapEventSource source,
required LatLng center,
required double zoom})
: super(source: source, center: center, zoom: zoom);
const MapEventRotateStart({
required super.source,
required super.center,
required super.zoom,
});
}

class MapEventRotateEnd extends MapEvent {
MapEventRotateEnd(
{required MapEventSource source,
required LatLng center,
required double zoom})
: super(source: source, center: center, zoom: zoom);
const MapEventRotateEnd({
required super.source,
required super.center,
required super.zoom,
});
}

0 comments on commit 84b0029

Please sign in to comment.