@@ -78,7 +78,6 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
7878 late double _lastRotation;
7979 late double _lastScale;
8080 late Offset _lastFocalLocal;
81- late Offset _prevFocalLocal;
8281 late LatLng _mapCenterStart;
8382 late double _mapZoomStart;
8483 late Offset _focalStartLocal;
@@ -540,8 +539,7 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
540539
541540 _mapZoomStart = _camera.zoom;
542541 _mapCenterStart = _camera.center;
543- _focalStartLocal =
544- _lastFocalLocal = _prevFocalLocal = details.localFocalPoint;
542+ _focalStartLocal = _lastFocalLocal = details.localFocalPoint;
545543 _focalStartLatLng = _camera.offsetToCrs (_focalStartLocal);
546544
547545 _dragStarted = false ;
@@ -569,7 +567,6 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
569567
570568 _lastRotation = currentRotation;
571569 _lastScale = details.scale;
572- _prevFocalLocal = _lastFocalLocal;
573570 _lastFocalLocal = details.localFocalPoint;
574571 }
575572
@@ -792,28 +789,13 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
792789 return ;
793790 }
794791
795- // Use the tracked offset to determine direction instead of the velocity
796- // direction, which can be incorrect on web when the pointer leaves the
797- // window. Use the final segment direction to correctly handle curved
798- // gestures where the user changes direction during the drag.
799- final flingOffset = _focalStartLocal - _lastFocalLocal;
800- final finalSegment = _prevFocalLocal - _lastFocalLocal;
801- final finalSegmentDistance = finalSegment.distance;
802-
803- // Use final segment direction if available, otherwise fall back to overall
804- // direction for edge cases where the final segment has no movement.
805- final Offset direction;
806- if (finalSegmentDistance > 0 ) {
807- direction = finalSegment / finalSegmentDistance;
808- } else {
809- final flingDistance = flingOffset.distance;
810- direction = flingOffset / flingDistance;
811- }
792+ final direction = details.velocity.pixelsPerSecond / magnitude;
812793 final distance = (Offset .zero & _camera.nonRotatedSize).shortestSide;
813794
795+ final flingOffset = _focalStartLocal - _lastFocalLocal;
814796 _flingAnimation = Tween <Offset >(
815797 begin: flingOffset,
816- end: flingOffset + direction * distance,
798+ end: flingOffset - direction * distance,
817799 ).animate (_flingController);
818800
819801 _flingController
0 commit comments