From c6ebb21cfdd3375fd2e8b4dd9dbf116c8b578fc9 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:26:46 -0500 Subject: [PATCH 01/27] Restore upstream BSD-3 attribution to google_map_animation - LICENSE: original BSD-3-Clause notice (Manish Relani) plus fork section - README: state this is a fork, drop ToolRides wording, fix links and GIF alt - lib/src: add origin header to copied files - doc/notes/upstream.md: draft message for the original author --- LICENSE | 72 +++++++++++++------ README.md | 16 +++-- doc/notes/upstream.md | 26 +++++++ .../animations/delayed_curved_animaiton.dart | 4 ++ lib/src/animator/base/polyline_animator.dart | 4 ++ lib/src/animator/color_animator.dart | 4 ++ .../fade_in_progressive_animator.dart | 4 ++ lib/src/animator/snack_animator.dart | 4 ++ .../controllers/map_animation_controller.dart | 4 ++ lib/src/controllers/marker_controller.dart | 4 ++ lib/src/controllers/polyline_controller.dart | 4 ++ lib/src/managers/animated_marker_manager.dart | 4 ++ .../managers/animated_polyline_manager.dart | 4 ++ lib/src/model/animated_polyline.dart | 4 ++ lib/src/tween/bearing_tween.dart | 4 ++ lib/src/tween/location_tween.dart | 4 ++ lib/src/utils/spherical_util.dart | 4 ++ lib/src/utils/util.dart | 4 ++ 18 files changed, 147 insertions(+), 27 deletions(-) create mode 100644 doc/notes/upstream.md diff --git a/LICENSE b/LICENSE index 0e37f3b..9a8f7e6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,51 @@ -MIT License - -Copyright (c) 2025 ToolRides - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +This package is a fork of google_map_animation by Manish Relani +(https://github.com/manishrelani/google_map_animation). The original code is +distributed under the BSD 3-Clause License, reproduced in section 1 below. +Changes and additions made in this fork are covered by section 2. + +================================================================================ +1. Original work: google_map_animation +================================================================================ + +BSD 3-Clause License + +Copyright (c) 2025, Manish Relani +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +================================================================================ +2. Modifications and additions in polyline_animation_plus +================================================================================ + +BSD 3-Clause License + +Copyright (c) 2025, Michael Anthony Valdiviezo Maza +All rights reserved. + +This section covers only the changes and new code added in this fork. It does +not replace or reduce the notice in section 1, which continues to apply to the +original code. The conditions and disclaimer are the same as in section 1. diff --git a/README.md b/README.md index abb1c87..4b27842 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # polyline_animation_plus +> Fork of [google_map_animation](https://github.com/manishrelani/google_map_animation) by Manish Relani (BSD-3-Clause). See [License](#-license). + A Flutter package for creating smooth, customizable polyline animations on Google Maps. Ideal for apps in transportation, delivery, logistics, tracking, or any project that needs animated route visualizations. ## 🎥 Demo

-Floating Bubble Overlay Demo +Animated polyline drawing on Google Maps
This animation represents how the plugin behaves

@@ -99,15 +101,15 @@ More complete examples can be found in the `/example` folder. ## 📚 Additional Information - Issues and feature requests: **GitHub Issues** -- Repository: https://github.com/MICHAELVM01/polyline_animation_plus +- Repository: https://github.com/VMichael1999/polyline_animation_plus - Contributions are welcome! Submit PRs to improve animations or extend support. -- This package is developed by **ToolRides** for advanced route visualizations in transportation and mobility apps. +- Based on [google_map_animation](https://github.com/manishrelani/google_map_animation) by Manish Relani. ## 👤 Author / Developer **Michael Anthony Valdiviezo Maza** -Flutter & Mobile Developer focused on mobility, ride‑hailing, logistics and real‑time map experiences. Creator of ToolRides solutions and open‑source packages for advanced transportation interfaces. +Flutter & Mobile Developer focused on mobility, ride‑hailing, logistics and real‑time map experiences. Maintainer of this fork, which builds on the original work of Manish Relani. **Areas of focus** - Google Maps & geolocation (polylines, tracking, animations) @@ -116,7 +118,7 @@ Flutter & Mobile Developer focused on mobility, ride‑hailing, logistics and re - White‑label transportation platforms (B2B & B2C) **Connect** -- GitHub: https://github.com/MICHAELVM01 +- GitHub: https://github.com/VMichael1999 If you use this package in your project, feel free to open an issue or PR — contributions and ideas are welcome. @@ -125,4 +127,6 @@ If you use this package in your project, feel free to open an issue or PR — co ## 📄 License -MIT License — feel free to use it in commercial and open‑source projects. +BSD 3-Clause. The original code is © 2025 Manish Relani ([google_map_animation](https://github.com/manishrelani/google_map_animation)); changes in this fork are © 2025 Michael Anthony Valdiviezo Maza. Both notices are in [LICENSE](LICENSE) and must be kept in copies. + +Fork additions: see [CHANGELOG](CHANGELOG.md). diff --git a/doc/notes/upstream.md b/doc/notes/upstream.md new file mode 100644 index 0000000..ef04d75 --- /dev/null +++ b/doc/notes/upstream.md @@ -0,0 +1,26 @@ +# Borrador de mensaje para el autor original + +Para enviar por el dueño del repo (no se ha contactado a nadie). +Destino: https://github.com/manishrelani/google_map_animation + +--- + +Hola Manish, + +Mantengo `polyline_animation_plus` +(https://github.com/VMichael1999/polyline_animation_plus), un fork de tu +paquete `google_map_animation`. Restauré tu aviso BSD-3-Clause en `LICENSE`, +lo mencioné en el README y agregué un encabezado de origen en los archivos +copiados. Perdón por no haberlo hecho desde la primera versión. + +Planeo corregir y agregar, entre otras cosas: +- retrasos de animación que acortaban la duración, +- puntos equidistantes en `generateEquidistantPolylineByDuration`, +- modo `latestOnly` para marcadores, seguimiento de vehículo sobre ruta, +- pausa/seek de animaciones, animators nuevos y cámara que sigue al vehículo. + +Si te interesa, puedo enviarlas como PR a tu repo en lugar de mantener el +fork aparte. Dime qué prefieres. + +Gracias por el trabajo original, +Michael diff --git a/lib/src/animations/delayed_curved_animaiton.dart b/lib/src/animations/delayed_curved_animaiton.dart index 18f99f1..66428b4 100644 --- a/lib/src/animations/delayed_curved_animaiton.dart +++ b/lib/src/animations/delayed_curved_animaiton.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'dart:math' as math; import 'package:flutter/material.dart'; diff --git a/lib/src/animator/base/polyline_animator.dart b/lib/src/animator/base/polyline_animator.dart index b5b3e9b..9cf08a6 100644 --- a/lib/src/animator/base/polyline_animator.dart +++ b/lib/src/animator/base/polyline_animator.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/animator/color_animator.dart b/lib/src/animator/color_animator.dart index 45094ad..f81384f 100644 --- a/lib/src/animator/color_animator.dart +++ b/lib/src/animator/color_animator.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; diff --git a/lib/src/animator/fade_in_progressive_animator.dart b/lib/src/animator/fade_in_progressive_animator.dart index f596d22..48b7157 100644 --- a/lib/src/animator/fade_in_progressive_animator.dart +++ b/lib/src/animator/fade_in_progressive_animator.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; diff --git a/lib/src/animator/snack_animator.dart b/lib/src/animator/snack_animator.dart index 3dc91e7..3d9e4b6 100644 --- a/lib/src/animator/snack_animator.dart +++ b/lib/src/animator/snack_animator.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; diff --git a/lib/src/controllers/map_animation_controller.dart b/lib/src/controllers/map_animation_controller.dart index fe89dbe..a66f5eb 100644 --- a/lib/src/controllers/map_animation_controller.dart +++ b/lib/src/controllers/map_animation_controller.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/controllers/marker_controller.dart b/lib/src/controllers/marker_controller.dart index 9f3d39e..e1af95c 100644 --- a/lib/src/controllers/marker_controller.dart +++ b/lib/src/controllers/marker_controller.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'dart:collection'; import 'package:flutter/material.dart'; diff --git a/lib/src/controllers/polyline_controller.dart b/lib/src/controllers/polyline_controller.dart index 964cc76..f6dde57 100644 --- a/lib/src/controllers/polyline_controller.dart +++ b/lib/src/controllers/polyline_controller.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/managers/animated_marker_manager.dart b/lib/src/managers/animated_marker_manager.dart index 578f4ec..695f1e5 100644 --- a/lib/src/managers/animated_marker_manager.dart +++ b/lib/src/managers/animated_marker_manager.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/managers/animated_polyline_manager.dart b/lib/src/managers/animated_polyline_manager.dart index 72c997c..f82f886 100644 --- a/lib/src/managers/animated_polyline_manager.dart +++ b/lib/src/managers/animated_polyline_manager.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/model/animated_polyline.dart b/lib/src/model/animated_polyline.dart index 54c5ae3..6306cde 100644 --- a/lib/src/model/animated_polyline.dart +++ b/lib/src/model/animated_polyline.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; diff --git a/lib/src/tween/bearing_tween.dart b/lib/src/tween/bearing_tween.dart index 7a5b9bc..bff2057 100644 --- a/lib/src/tween/bearing_tween.dart +++ b/lib/src/tween/bearing_tween.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import '../utils/spherical_util.dart'; diff --git a/lib/src/tween/location_tween.dart b/lib/src/tween/location_tween.dart index f12b929..1f4fad0 100644 --- a/lib/src/tween/location_tween.dart +++ b/lib/src/tween/location_tween.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/utils/spherical_util.dart b/lib/src/utils/spherical_util.dart index 3f73f0f..ba192f2 100644 --- a/lib/src/utils/spherical_util.dart +++ b/lib/src/utils/spherical_util.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'dart:math'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/utils/util.dart b/lib/src/utils/util.dart index e1a5354..641db1d 100644 --- a/lib/src/utils/util.dart +++ b/lib/src/utils/util.dart @@ -1,3 +1,7 @@ +// Based on google_map_animation by Manish Relani (BSD-3-Clause). +// https://github.com/manishrelani/google_map_animation +// See LICENSE for the original notice and the changes made in this fork. + import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/utils/spherical_util.dart'; From 94794749ac95886b84a59896b983d074ac030f12 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:27:52 -0500 Subject: [PATCH 02/27] Apply dart format to lib Formatting only, no behavior change. --- .../animations/delayed_curved_animaiton.dart | 22 ++++++++++++++----- lib/src/animator/color_animator.dart | 6 +---- .../fade_in_progressive_animator.dart | 2 -- lib/src/animator/snack_animator.dart | 1 - lib/src/controllers/marker_controller.dart | 5 +---- lib/src/managers/animated_marker_manager.dart | 16 ++++++++------ lib/src/model/animated_polyline.dart | 6 +---- lib/src/utils/util.dart | 1 - 8 files changed, 29 insertions(+), 30 deletions(-) diff --git a/lib/src/animations/delayed_curved_animaiton.dart b/lib/src/animations/delayed_curved_animaiton.dart index 66428b4..332b787 100644 --- a/lib/src/animations/delayed_curved_animaiton.dart +++ b/lib/src/animations/delayed_curved_animaiton.dart @@ -19,11 +19,19 @@ class DelayedCurvedAnimation extends CurvedAnimation { this.delayEnd = Duration.zero, Curve curve = Curves.linear, }) : animationDuration = Duration( - microseconds: totalDuration.inMicroseconds - delayStart.inMicroseconds - delayEnd.inMicroseconds, + microseconds: + totalDuration.inMicroseconds - + delayStart.inMicroseconds - + delayEnd.inMicroseconds, ), super( parent: controller, - curve: _calculateAnimationInterval(totalDuration, delayStart, delayEnd, curve), + curve: _calculateAnimationInterval( + totalDuration, + delayStart, + delayEnd, + curve, + ), ); static Interval _calculateAnimationInterval( @@ -35,7 +43,8 @@ class DelayedCurvedAnimation extends CurvedAnimation { final totalMicroseconds = totalDuration.inMicroseconds; // Validation - if (delayStart.inMicroseconds + delayEnd.inMicroseconds >= totalMicroseconds) { + if (delayStart.inMicroseconds + delayEnd.inMicroseconds >= + totalMicroseconds) { throw ArgumentError( 'Combined delays (${delayStart.inMilliseconds}ms + ${delayEnd.inMilliseconds}ms) ' 'cannot exceed total duration (${totalDuration.inMilliseconds}ms)', @@ -62,8 +71,11 @@ class DelayedCurvedAnimation extends CurvedAnimation { return math.max(0.0, math.min(1.0, (value - startRatio) / animationRatio)); } - bool get isInStartDelay => parent.value < (delayStart.inMicroseconds / totalDuration.inMicroseconds); - bool get isInEndDelay => parent.value > (1 - delayEnd.inMicroseconds / totalDuration.inMicroseconds); + bool get isInStartDelay => + parent.value < (delayStart.inMicroseconds / totalDuration.inMicroseconds); + bool get isInEndDelay => + parent.value > + (1 - delayEnd.inMicroseconds / totalDuration.inMicroseconds); @override bool get isAnimating => !isInStartDelay && !isInEndDelay; diff --git a/lib/src/animator/color_animator.dart b/lib/src/animator/color_animator.dart index f81384f..58cd5da 100644 --- a/lib/src/animator/color_animator.dart +++ b/lib/src/animator/color_animator.dart @@ -6,8 +6,6 @@ import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; - - class ColorTransitionAnimation extends PolylineAnimator { final List colors; @@ -32,8 +30,6 @@ class ColorTransitionAnimation extends PolylineAnimator { colorProgress, ); - return polyline.copyWith( - colorParam: interpolatedColor, - ); + return polyline.copyWith(colorParam: interpolatedColor); } } diff --git a/lib/src/animator/fade_in_progressive_animator.dart b/lib/src/animator/fade_in_progressive_animator.dart index 48b7157..3650343 100644 --- a/lib/src/animator/fade_in_progressive_animator.dart +++ b/lib/src/animator/fade_in_progressive_animator.dart @@ -6,8 +6,6 @@ import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; - - class FadeInProgressiveAnimator extends PolylineAnimator { const FadeInProgressiveAnimator({ super.duration = const Duration(seconds: 5), diff --git a/lib/src/animator/snack_animator.dart b/lib/src/animator/snack_animator.dart index 3d9e4b6..d23c49d 100644 --- a/lib/src/animator/snack_animator.dart +++ b/lib/src/animator/snack_animator.dart @@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; - class SnackAnimator extends PolylineAnimator { const SnackAnimator({ super.duration = const Duration(seconds: 2), diff --git a/lib/src/controllers/marker_controller.dart b/lib/src/controllers/marker_controller.dart index e1af95c..e104f1c 100644 --- a/lib/src/controllers/marker_controller.dart +++ b/lib/src/controllers/marker_controller.dart @@ -33,10 +33,7 @@ class MarkerController { end: marker.position, ); - _bearingTween = BearingTween( - begin: marker.rotation, - end: marker.rotation, - ); + _bearingTween = BearingTween(begin: marker.rotation, end: marker.rotation); _locationTween.animate(_animationController); _bearingTween.animate(_animationController); diff --git a/lib/src/managers/animated_marker_manager.dart b/lib/src/managers/animated_marker_manager.dart index 695f1e5..3370741 100644 --- a/lib/src/managers/animated_marker_manager.dart +++ b/lib/src/managers/animated_marker_manager.dart @@ -17,9 +17,10 @@ class AnimatedMarkersManager { // 16.67 ms per frame for 60 FPS (1000 ms / 60 FPS) ~= 16.67 ms totalFrames = (duration.inMilliseconds / 16.67).round(); - _animationController = AnimationController(vsync: vsync, duration: duration) - ..addStatusListener(_statusListener) - ..addListener(listener); + _animationController = + AnimationController(vsync: vsync, duration: duration) + ..addStatusListener(_statusListener) + ..addListener(listener); } late final int totalFrames; @@ -38,10 +39,11 @@ class AnimatedMarkersManager { void push(Set markers) { for (var marker in markers) { - final controller = _controllers[marker.markerId] ??= MarkerController( - marker: marker, - animationController: _animationController, - ); + final controller = + _controllers[marker.markerId] ??= MarkerController( + marker: marker, + animationController: _animationController, + ); controller.pushToQueue(marker); } diff --git a/lib/src/model/animated_polyline.dart b/lib/src/model/animated_polyline.dart index 6306cde..b3bc4de 100644 --- a/lib/src/model/animated_polyline.dart +++ b/lib/src/model/animated_polyline.dart @@ -5,17 +5,13 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; - class AnimatedPolyline { final Polyline polyline; // If null, the polyline consider as satic. final PolylineAnimator? polylineAnimator; - const AnimatedPolyline({ - required this.polyline, - this.polylineAnimator, - }); + const AnimatedPolyline({required this.polyline, this.polylineAnimator}); @override bool operator ==(Object other) { diff --git a/lib/src/utils/util.dart b/lib/src/utils/util.dart index 641db1d..2ca7eb6 100644 --- a/lib/src/utils/util.dart +++ b/lib/src/utils/util.dart @@ -2,7 +2,6 @@ // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. - import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/utils/spherical_util.dart'; From 01599d7aeed186306f94ee0839c6abe77a997521 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:27:52 -0500 Subject: [PATCH 03/27] Fix delays shortening the polyline animation The AnimationController lasted only `duration` while DelayedCurvedAnimation computed its interval over duration + delayStart + delayEnd, so delays ate into the drawing time. The controller now runs for the whole cycle. Behavior change: animations with delays now take the full `duration` to draw. --- lib/src/controllers/polyline_controller.dart | 14 +++-- .../controllers/polyline_controller_test.dart | 56 +++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 test/controllers/polyline_controller_test.dart diff --git a/lib/src/controllers/polyline_controller.dart b/lib/src/controllers/polyline_controller.dart index f6dde57..8f03062 100644 --- a/lib/src/controllers/polyline_controller.dart +++ b/lib/src/controllers/polyline_controller.dart @@ -34,8 +34,15 @@ class PolylineAnimationController { } void _initialize() { + // The controller must run for the whole cycle (delays included), because + // DelayedCurvedAnimation computes its interval over that total. + final totalDuration = + polylineAnimator.duration + + polylineAnimator.delayStart + + polylineAnimator.delayEnd; + _controller = - AnimationController(vsync: vsync, duration: polylineAnimator.duration) + AnimationController(vsync: vsync, duration: totalDuration) ..addListener(_listener) ..addStatusListener(_statusListener); @@ -43,10 +50,7 @@ class PolylineAnimationController { polylineAnimator.delayEnd != Duration.zero) { _curvedAnimation = DelayedCurvedAnimation( controller: _controller, - totalDuration: - polylineAnimator.duration + - polylineAnimator.delayStart + - polylineAnimator.delayEnd, + totalDuration: totalDuration, delayStart: polylineAnimator.delayStart, delayEnd: polylineAnimator.delayEnd, curve: polylineAnimator.curve, diff --git a/test/controllers/polyline_controller_test.dart b/test/controllers/polyline_controller_test.dart new file mode 100644 index 0000000..1b2d61e --- /dev/null +++ b/test/controllers/polyline_controller_test.dart @@ -0,0 +1,56 @@ +import 'package:flutter/animation.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; +import 'package:polyline_animation_plus/src/controllers/polyline_controller.dart'; + +class _RecordingAnimator extends PolylineAnimator { + const _RecordingAnimator({ + required super.duration, + super.delayStart, + super.delayEnd, + }); + + static final progress = []; + + @override + Polyline animate(Polyline polyline, double progress) { + _RecordingAnimator.progress.add(progress); + return polyline; + } +} + +void main() { + const polyline = Polyline( + polylineId: PolylineId('p'), + points: [LatLng(0, 0), LatLng(0, 1)], + ); + + setUp(_RecordingAnimator.progress.clear); + + testWidgets('delayStart is added to duration instead of eating into it', ( + tester, + ) async { + final controller = PolylineAnimationController( + vsync: tester, + polyline: polyline, + polylineListener: (_) {}, + polylineAnimator: const _RecordingAnimator( + duration: Duration(seconds: 4), + delayStart: Duration(seconds: 1), + ), + ); + + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + expect(_RecordingAnimator.progress.last, 0.0); + + await tester.pump(const Duration(seconds: 2)); + expect(_RecordingAnimator.progress.last, closeTo(0.5, 1e-6)); + + await tester.pump(const Duration(seconds: 2)); + expect(_RecordingAnimator.progress.last, 1.0); + + controller.dispose(); + }); +} From dfabc72e61c36fbde00e3c173ff73f0554ed791c Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:28:23 -0500 Subject: [PATCH 04/27] Fix generateEquidistantPolylineByDuration spacing and endpoints - the first point was emitted twice - the offset carried across segment joins had the wrong sign, so spacing drifted after every join - the last point of the path was never included Also returns the path unchanged when its total length is zero, which would otherwise loop forever with a zero spacing. --- lib/src/utils/util.dart | 32 ++++++++----- test/utils/map_animation_utils_test.dart | 61 ++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 test/utils/map_animation_utils_test.dart diff --git a/lib/src/utils/util.dart b/lib/src/utils/util.dart index 2ca7eb6..930acf6 100644 --- a/lib/src/utils/util.dart +++ b/lib/src/utils/util.dart @@ -10,6 +10,9 @@ import 'package:polyline_animation_plus/src/utils/spherical_util.dart'; final class MapAnimationUtils { MapAnimationUtils._(); + /// Tolerance used to absorb floating point error when comparing distances. + static const _epsilonMeters = 1e-6; + static List generateEquidistantPolylineByDuration({ required List path, required Duration duration, @@ -38,24 +41,31 @@ final class MapAnimationUtils { List path, double spacingMeters, ) { - if (path.length < 2) return path; + if (path.length < 2 || spacingMeters <= 0) return path; + + final result = [path.first]; - List result = [path.first]; - double remaining = 0.0; + // Distance travelled since the last emitted point. + var carry = 0.0; for (int i = 0; i < path.length - 1; i++) { - LatLng start = path[i]; - LatLng end = path[i + 1]; + final start = path[i]; + final end = path[i + 1]; final segmentLength = SphericalUtil.computeDistanceBetween(start, end); - double distanceCovered = 0.0; - while ((remaining + distanceCovered) < segmentLength) { - double fraction = (remaining + distanceCovered) / segmentLength; - result.add(SphericalUtil.interpolate(start, end, fraction)); - distanceCovered += spacingMeters; + // Distance along this segment to the next point to emit. + var next = spacingMeters - carry; + while (next <= segmentLength + _epsilonMeters) { + result.add(SphericalUtil.interpolate(start, end, next / segmentLength)); + next += spacingMeters; } + carry = spacingMeters - (next - segmentLength); + } - remaining = (remaining + segmentLength - distanceCovered) % spacingMeters; + final last = path.last; + if (SphericalUtil.computeDistanceBetween(result.last, last) > + _epsilonMeters) { + result.add(last); } return result; diff --git a/test/utils/map_animation_utils_test.dart b/test/utils/map_animation_utils_test.dart new file mode 100644 index 0000000..91cf682 --- /dev/null +++ b/test/utils/map_animation_utils_test.dart @@ -0,0 +1,61 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; +import 'package:polyline_animation_plus/src/utils/spherical_util.dart'; + +/// A point [meters] east of the origin along the equator. +LatLng _eastOf(double meters) => + LatLng(0, meters / SphericalUtil.earthRadius * 180 / 3.141592653589793); + +void main() { + group('generateEquidistantPolylineByDuration', () { + // Two straight segments of 9 m and 11 m (20 m total). 128 ms at 16 ms per + // frame is 8 steps, so the spacing is 2.5 m. The junction at 9 m is not a + // multiple of the spacing. + final path = [_eastOf(0), _eastOf(9), _eastOf(20)]; + final points = MapAnimationUtils.generateEquidistantPolylineByDuration( + path: path, + duration: const Duration(milliseconds: 128), + ); + + test('starts at the first point without duplicating it', () { + expect(points.first, path.first); + expect(points[1], isNot(path.first)); + }); + + test('keeps the same distance between consecutive points', () { + for (var i = 0; i < points.length - 1; i++) { + final d = SphericalUtil.computeDistanceBetween( + points[i], + points[i + 1], + ); + expect(d, closeTo(2.5, 1e-3), reason: 'between point $i and ${i + 1}'); + } + }); + + test('ends at the last point of the path', () { + expect(points.last.latitude, closeTo(path.last.latitude, 1e-9)); + expect(points.last.longitude, closeTo(path.last.longitude, 1e-9)); + expect(points, hasLength(9)); + }); + + test('adds the last point when it is not a multiple of the spacing', () { + // 20 m / 6 steps = 3.33 m; the last gap is shorter than the spacing. + final shortGap = [_eastOf(0), _eastOf(10), _eastOf(21)]; + final result = MapAnimationUtils.generateEquidistantPolylineByDuration( + path: shortGap, + duration: const Duration(milliseconds: 96), + ); + expect(result.last.longitude, closeTo(shortGap.last.longitude, 1e-9)); + }); + + test('returns the path unchanged when all points coincide', () { + final same = [_eastOf(5), _eastOf(5)]; + final result = MapAnimationUtils.generateEquidistantPolylineByDuration( + path: same, + duration: const Duration(milliseconds: 128), + ); + expect(result, same); + }); + }); +} From b98aedfcb8c82b478e9cd09b301b244152c512c1 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:28:49 -0500 Subject: [PATCH 05/27] Include delays and colors in animator equality PolylineAnimator ignored delayStart and delayEnd in == and hashCode, and ColorTransitionAnimation ignored its colors, so the polyline manager kept the old animation when only those values changed. --- lib/src/animator/base/polyline_animator.dart | 19 +++++---- lib/src/animator/color_animator.dart | 10 +++++ test/animator/animator_equality_test.dart | 41 ++++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 test/animator/animator_equality_test.dart diff --git a/lib/src/animator/base/polyline_animator.dart b/lib/src/animator/base/polyline_animator.dart index 9cf08a6..d06fa3c 100644 --- a/lib/src/animator/base/polyline_animator.dart +++ b/lib/src/animator/base/polyline_animator.dart @@ -53,16 +53,21 @@ abstract class PolylineAnimator { curve == other.curve && repeat == other.repeat && repeatCount == other.repeatCount && - reverse == other.reverse; + reverse == other.reverse && + delayStart == other.delayStart && + delayEnd == other.delayEnd; } @override - int get hashCode => - duration.hashCode ^ - curve.hashCode ^ - repeat.hashCode ^ - (repeatCount?.hashCode ?? 0) ^ - reverse.hashCode; + int get hashCode => Object.hash( + duration, + curve, + repeat, + repeatCount, + reverse, + delayStart, + delayEnd, + ); @override String toString() { diff --git a/lib/src/animator/color_animator.dart b/lib/src/animator/color_animator.dart index 58cd5da..80d606a 100644 --- a/lib/src/animator/color_animator.dart +++ b/lib/src/animator/color_animator.dart @@ -2,6 +2,7 @@ // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; @@ -32,4 +33,13 @@ class ColorTransitionAnimation extends PolylineAnimator { return polyline.copyWith(colorParam: interpolatedColor); } + + @override + bool operator ==(Object other) => + super == other && + other is ColorTransitionAnimation && + listEquals(colors, other.colors); + + @override + int get hashCode => Object.hash(super.hashCode, Object.hashAll(colors)); } diff --git a/test/animator/animator_equality_test.dart b/test/animator/animator_equality_test.dart new file mode 100644 index 0000000..c1bfdde --- /dev/null +++ b/test/animator/animator_equality_test.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; + +void main() { + group('PolylineAnimator equality', () { + test('differs when delayStart changes', () { + const a = FadeInProgressiveAnimator(delayStart: Duration(seconds: 1)); + const b = FadeInProgressiveAnimator(delayStart: Duration(seconds: 2)); + expect(a, isNot(b)); + }); + + test('differs when delayEnd changes', () { + const a = FadeInProgressiveAnimator(delayEnd: Duration(seconds: 1)); + const b = FadeInProgressiveAnimator(delayEnd: Duration(seconds: 2)); + expect(a, isNot(b)); + }); + + test('equal animators share the hash code', () { + const a = FadeInProgressiveAnimator(delayStart: Duration(seconds: 1)); + const b = FadeInProgressiveAnimator(delayStart: Duration(seconds: 1)); + expect(a, b); + expect(a.hashCode, b.hashCode); + }); + }); + + group('ColorTransitionAnimation equality', () { + test('differs when colors change', () { + const a = ColorTransitionAnimation(colors: [Colors.red, Colors.blue]); + const b = ColorTransitionAnimation(colors: [Colors.red, Colors.green]); + expect(a, isNot(b)); + }); + + test('equal colors give equal animators and hash codes', () { + final a = ColorTransitionAnimation(colors: [Colors.red, Colors.blue]); + final b = ColorTransitionAnimation(colors: [Colors.red, Colors.blue]); + expect(a, b); + expect(a.hashCode, b.hashCode); + }); + }); +} From 25084c732317fd601228b76df7302695b866b061 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:28:54 -0500 Subject: [PATCH 06/27] Expose repeat and delay parameters on SnackAnimator and ColorTransitionAnimation SnackAnimator now accepts delayStart and delayEnd. ColorTransitionAnimation now accepts repeatCount, reverse, delayStart and delayEnd. Defaults keep the previous behavior. --- lib/src/animator/color_animator.dart | 4 ++++ lib/src/animator/snack_animator.dart | 2 ++ test/animator/animator_params_test.dart | 29 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 test/animator/animator_params_test.dart diff --git a/lib/src/animator/color_animator.dart b/lib/src/animator/color_animator.dart index 80d606a..aee2203 100644 --- a/lib/src/animator/color_animator.dart +++ b/lib/src/animator/color_animator.dart @@ -15,6 +15,10 @@ class ColorTransitionAnimation extends PolylineAnimator { super.duration = const Duration(seconds: 5), super.curve = Curves.linear, super.repeat = false, + super.repeatCount, + super.reverse, + super.delayStart, + super.delayEnd, }); @override diff --git a/lib/src/animator/snack_animator.dart b/lib/src/animator/snack_animator.dart index d23c49d..3b13a0c 100644 --- a/lib/src/animator/snack_animator.dart +++ b/lib/src/animator/snack_animator.dart @@ -13,6 +13,8 @@ class SnackAnimator extends PolylineAnimator { super.repeat = false, super.repeatCount, super.reverse = false, + super.delayStart, + super.delayEnd, }); @override diff --git a/test/animator/animator_params_test.dart b/test/animator/animator_params_test.dart new file mode 100644 index 0000000..081df64 --- /dev/null +++ b/test/animator/animator_params_test.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; + +void main() { + test('SnackAnimator accepts delays', () { + const animator = SnackAnimator( + delayStart: Duration(seconds: 1), + delayEnd: Duration(seconds: 2), + ); + expect(animator.delayStart, const Duration(seconds: 1)); + expect(animator.delayEnd, const Duration(seconds: 2)); + }); + + test('ColorTransitionAnimation accepts repeatCount, reverse and delays', () { + const animator = ColorTransitionAnimation( + colors: [Colors.red, Colors.blue], + repeat: true, + repeatCount: 3, + reverse: true, + delayStart: Duration(seconds: 1), + delayEnd: Duration(seconds: 2), + ); + expect(animator.repeatCount, 3); + expect(animator.reverse, isTrue); + expect(animator.delayStart, const Duration(seconds: 1)); + expect(animator.delayEnd, const Duration(seconds: 2)); + }); +} From abeea2da54cf3817f88835571a1c5f0e85305176 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:29:23 -0500 Subject: [PATCH 07/27] Keep marker rotation when it does not move; add useMarkerRotation computeHeading between identical positions is 0, so a stationary marker snapped to face north. Moves shorter than 0.5 m now keep the current rotation. useMarkerRotation (default false) uses Marker.rotation as the target rotation instead of the heading, matching the name used by the original package. --- .../controllers/map_animation_controller.dart | 6 ++ lib/src/controllers/marker_controller.dart | 23 ++++++- lib/src/managers/animated_marker_manager.dart | 4 ++ test/controllers/marker_controller_test.dart | 65 +++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test/controllers/marker_controller_test.dart diff --git a/lib/src/controllers/map_animation_controller.dart b/lib/src/controllers/map_animation_controller.dart index a66f5eb..3771609 100644 --- a/lib/src/controllers/map_animation_controller.dart +++ b/lib/src/controllers/map_animation_controller.dart @@ -19,6 +19,10 @@ final class MapAnimationController { final int mapId; + /// Use [Marker.rotation] as the rotation of animated markers instead of the + /// heading between consecutive positions. Default is false. + final bool useMarkerRotation; + /// Duration for marker animation transitions. Default is 2 second. final Duration markersAnimationDuration; @@ -29,6 +33,7 @@ final class MapAnimationController { Set polylines = const {}, this.markersAnimationDuration = const Duration(milliseconds: 2000), this.markerListener, + this.useMarkerRotation = false, }) { _initialize(markers, polylines); } @@ -59,6 +64,7 @@ final class MapAnimationController { duration: markersAnimationDuration, onUpdateMarkers: _updateMarker, onRemoveMarkers: _removeMarker, + useMarkerRotation: useMarkerRotation, ); _animatedMarkersManager.push(markerSet); diff --git a/lib/src/controllers/marker_controller.dart b/lib/src/controllers/marker_controller.dart index e104f1c..ce2c0fe 100644 --- a/lib/src/controllers/marker_controller.dart +++ b/lib/src/controllers/marker_controller.dart @@ -9,8 +9,17 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf import '../tween/bearing_tween.dart'; import '../tween/location_tween.dart'; +import '../utils/spherical_util.dart'; class MarkerController { + /// Moves shorter than this keep the current rotation, because the heading + /// between two (almost) identical positions is meaningless. + static const double minMoveMeters = 0.5; + + /// When true the rotation comes from [Marker.rotation] instead of the + /// heading between positions. + final bool useMarkerRotation; + final AnimationController _animationController; late final LocationTween _locationTween; @@ -26,6 +35,7 @@ class MarkerController { MarkerController({ required Marker marker, required AnimationController animationController, + this.useMarkerRotation = false, }) : _currentMarker = marker, _animationController = animationController { _locationTween = LocationTween( @@ -54,9 +64,20 @@ class MarkerController { } void _setupTo(Marker m) { + final moved = + SphericalUtil.computeDistanceBetween(_locationTween.end, m.position) >= + minMoveMeters; + _currentMarker = m; _locationTween.swap(m.position); - _bearingTween.swap(_locationTween.bearing); + + if (useMarkerRotation) { + _bearingTween.swap(m.rotation); + } else if (moved) { + _bearingTween.swap(_locationTween.bearing); + } else { + _bearingTween.swap(_bearingTween.end); + } } Marker animate(double t) { diff --git a/lib/src/managers/animated_marker_manager.dart b/lib/src/managers/animated_marker_manager.dart index 3370741..ff315dc 100644 --- a/lib/src/managers/animated_marker_manager.dart +++ b/lib/src/managers/animated_marker_manager.dart @@ -13,6 +13,7 @@ class AnimatedMarkersManager { required Duration duration, required this.onUpdateMarkers, required this.onRemoveMarkers, + this.useMarkerRotation = false, }) { // 16.67 ms per frame for 60 FPS (1000 ms / 60 FPS) ~= 16.67 ms totalFrames = (duration.inMilliseconds / 16.67).round(); @@ -26,6 +27,9 @@ class AnimatedMarkersManager { late final int totalFrames; late final AnimationController _animationController; + /// See [MarkerController.useMarkerRotation]. + final bool useMarkerRotation; + final ValueChanged> onUpdateMarkers; final ValueChanged> onRemoveMarkers; diff --git a/test/controllers/marker_controller_test.dart b/test/controllers/marker_controller_test.dart new file mode 100644 index 0000000..012743c --- /dev/null +++ b/test/controllers/marker_controller_test.dart @@ -0,0 +1,65 @@ +import 'package:flutter/animation.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/src/controllers/marker_controller.dart'; + +const _id = MarkerId('m'); +const _origin = LatLng(0, 0); +const _east = LatLng(0, 0.001); + +MarkerController _controller( + AnimationController animation, + Marker marker, { + bool useMarkerRotation = false, +}) => MarkerController( + marker: marker, + animationController: animation, + useMarkerRotation: useMarkerRotation, +); + +void main() { + late AnimationController animation; + + setUp(() => animation = AnimationController(vsync: const TestVSync())); + tearDown(() => animation.dispose()); + + test('a marker that does not move keeps its rotation', () { + final controller = _controller( + animation, + const Marker(markerId: _id, position: _origin, rotation: 90), + ); + controller.pushToQueue( + const Marker(markerId: _id, position: _origin, rotation: 90, alpha: 0.5), + ); + controller.setupNextMarker(); + + expect(controller.animate(0.0).rotation, 90); + expect(controller.animate(0.5).rotation, 90); + expect(controller.animate(1.0).rotation, 90); + }); + + test('a marker that moves rotates towards the heading', () { + final controller = _controller( + animation, + const Marker(markerId: _id, position: _origin), + ); + controller.pushToQueue(const Marker(markerId: _id, position: _east)); + controller.setupNextMarker(); + + expect(controller.animate(1.0).rotation, closeTo(90, 1e-6)); + }); + + test('useMarkerRotation takes the rotation from the marker', () { + final controller = _controller( + animation, + const Marker(markerId: _id, position: _origin), + useMarkerRotation: true, + ); + controller.pushToQueue( + const Marker(markerId: _id, position: _east, rotation: 45), + ); + controller.setupNextMarker(); + + expect(controller.animate(1.0).rotation, closeTo(45, 1e-6)); + }); +} From 261aada6cacf218de49744d5d17e98e129aec71e Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:29:25 -0500 Subject: [PATCH 08/27] Rename delayed_curved_animaiton.dart to delayed_curved_animation.dart Internal file, not exported. --- ...ayed_curved_animaiton.dart => delayed_curved_animation.dart} | 0 lib/src/controllers/polyline_controller.dart | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/src/animations/{delayed_curved_animaiton.dart => delayed_curved_animation.dart} (100%) diff --git a/lib/src/animations/delayed_curved_animaiton.dart b/lib/src/animations/delayed_curved_animation.dart similarity index 100% rename from lib/src/animations/delayed_curved_animaiton.dart rename to lib/src/animations/delayed_curved_animation.dart diff --git a/lib/src/controllers/polyline_controller.dart b/lib/src/controllers/polyline_controller.dart index 8f03062..b91c750 100644 --- a/lib/src/controllers/polyline_controller.dart +++ b/lib/src/controllers/polyline_controller.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; -import '../animations/delayed_curved_animaiton.dart'; +import '../animations/delayed_curved_animation.dart'; import '../animator/base/polyline_animator.dart'; /// Controls the animation of a polyline. From 25026d1b0a6cb421eedbc74f2437e1c30fcb3211 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:29:44 -0500 Subject: [PATCH 09/27] Document and test when onAnimationStop is called It is called once when the animation completes. It is not called on dispose or for endless repeating animations. Also tidies unused test code. --- lib/src/animator/base/polyline_animator.dart | 4 ++ .../controllers/polyline_controller_test.dart | 53 +++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/lib/src/animator/base/polyline_animator.dart b/lib/src/animator/base/polyline_animator.dart index d06fa3c..86339ec 100644 --- a/lib/src/animator/base/polyline_animator.dart +++ b/lib/src/animator/base/polyline_animator.dart @@ -36,6 +36,10 @@ abstract class PolylineAnimator { Polyline animate(Polyline polyline, double progress); + /// Called once when the animation reaches its end. + /// + /// It is not called when the animation is disposed or removed before it + /// finishes, nor for animations that repeat forever, because they never end. void onAnimationStop() {} @override diff --git a/test/controllers/polyline_controller_test.dart b/test/controllers/polyline_controller_test.dart index 1b2d61e..0f7dadc 100644 --- a/test/controllers/polyline_controller_test.dart +++ b/test/controllers/polyline_controller_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/animation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/polyline_animation_plus.dart'; @@ -8,10 +7,14 @@ class _RecordingAnimator extends PolylineAnimator { const _RecordingAnimator({ required super.duration, super.delayStart, - super.delayEnd, + super.repeat, }); static final progress = []; + static var stops = 0; + + @override + void onAnimationStop() => stops++; @override Polyline animate(Polyline polyline, double progress) { @@ -26,7 +29,10 @@ void main() { points: [LatLng(0, 0), LatLng(0, 1)], ); - setUp(_RecordingAnimator.progress.clear); + setUp(() { + _RecordingAnimator.progress.clear(); + _RecordingAnimator.stops = 0; + }); testWidgets('delayStart is added to duration instead of eating into it', ( tester, @@ -53,4 +59,45 @@ void main() { controller.dispose(); }); + + group('onAnimationStop', () { + PolylineAnimationController create(WidgetTester tester, bool repeat) => + PolylineAnimationController( + vsync: tester, + polyline: polyline, + polylineListener: (_) {}, + polylineAnimator: _RecordingAnimator( + duration: const Duration(seconds: 1), + repeat: repeat, + ), + ); + + testWidgets('is called once when the animation completes', (tester) async { + final controller = create(tester, false); + await tester.pump(); + await tester.pump(const Duration(seconds: 2)); + expect(_RecordingAnimator.stops, 1); + controller.dispose(); + }); + + testWidgets('is not called when disposed before completing', ( + tester, + ) async { + final controller = create(tester, false); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + controller.dispose(); + expect(_RecordingAnimator.stops, 0); + }); + + testWidgets('is not called by an endless repeating animation', ( + tester, + ) async { + final controller = create(tester, true); + await tester.pump(); + await tester.pump(const Duration(seconds: 5)); + expect(_RecordingAnimator.stops, 0); + controller.dispose(); + }); + }); } From 5ba1988eef65bc825d8d582a199e21eb44815b0a Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:37:43 -0500 Subject: [PATCH 10/27] Replace Color.withValues with withAlpha for older Flutter withValues needs Flutter 3.27. withAlpha works on every supported version. Adds a test for the fade-in phase of FadeInProgressiveAnimator. --- .../fade_in_progressive_animator.dart | 4 ++- .../fade_in_progressive_animator_test.dart | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/animator/fade_in_progressive_animator_test.dart diff --git a/lib/src/animator/fade_in_progressive_animator.dart b/lib/src/animator/fade_in_progressive_animator.dart index 3650343..1b54d6a 100644 --- a/lib/src/animator/fade_in_progressive_animator.dart +++ b/lib/src/animator/fade_in_progressive_animator.dart @@ -21,7 +21,9 @@ class FadeInProgressiveAnimator extends PolylineAnimator { Polyline animate(Polyline polyline, double progress) { if (progress <= 0.3) { return polyline.copyWith( - colorParam: polyline.color.withValues(alpha: progress / 0.3), + colorParam: polyline.color.withAlpha( + (progress / 0.3 * 255).round().clamp(0, 255), + ), ); } else { final animationProgress = (progress - 0.3) / 0.7; diff --git a/test/animator/fade_in_progressive_animator_test.dart b/test/animator/fade_in_progressive_animator_test.dart new file mode 100644 index 0000000..2911ef3 --- /dev/null +++ b/test/animator/fade_in_progressive_animator_test.dart @@ -0,0 +1,36 @@ +// `alpha` and `value` are deprecated on new Flutter but are the only options on +// the minimum supported version. +// ignore_for_file: deprecated_member_use + +import 'dart:ui'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; + +void main() { + const animator = FadeInProgressiveAnimator(); + const polyline = Polyline( + polylineId: PolylineId('p'), + color: Color(0xFF1565C0), + points: [LatLng(0, 0), LatLng(0, 1), LatLng(0, 2), LatLng(0, 3)], + ); + + test('fades in during the first 30% without moving the points', () { + final start = animator.animate(polyline, 0.0); + final middle = animator.animate(polyline, 0.15); + final end = animator.animate(polyline, 0.3); + + expect(start.color.alpha, 0); + expect(middle.color.alpha, closeTo(128, 1)); + expect(end.color.alpha, 255); + expect(middle.color.value & 0x00FFFFFF, 0x1565C0); + expect(middle.points, polyline.points); + }); + + test('erases the polyline from its start afterwards', () { + expect(animator.animate(polyline, 0.3).points, polyline.points); + expect(animator.animate(polyline, 0.65).points, hasLength(2)); + expect(animator.animate(polyline, 1.0).points, isEmpty); + }); +} From 7c308aa0c36674a4a7c7814cec1d91f565da8c1d Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:38:15 -0500 Subject: [PATCH 11/27] Declare real SDK range, platforms and project links - sdk >=3.4.0, flutter >=3.22.0 (was flutter >=1.17.0) - google_maps_flutter_platform_interface ^2.10.0, the first release that supports Flutter 3.22; tests pass against 2.10.0 and the latest version - flutter_lints ^4.0.0 so the package still resolves on Dart 3.4 - platforms: android, ios, web - repository links point to VMichael1999 --- pubspec.yaml | 23 ++++++++++++-------- test/animator/animator_equality_test.dart | 3 +++ test/controllers/marker_controller_test.dart | 11 +++++----- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 265026a..d80a803 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,27 +1,32 @@ name: polyline_animation_plus description: "A Flutter package for creating smooth, customizable polyline animations on Google Maps, ideal for transport, delivery, and route-visualization applications." version: 1.0.4 -homepage: https://github.com/MICHAELVM01/polyline_animation_plus -repository: https://github.com/MICHAELVM01/polyline_animation_plus -issue_tracker: https://github.com/MICHAELVM01/polyline_animation_plus/issues -documentation: https://github.com/MICHAELVM01/polyline_animation_plus +homepage: https://github.com/VMichael1999/polyline_animation_plus +repository: https://github.com/VMichael1999/polyline_animation_plus +issue_tracker: https://github.com/VMichael1999/polyline_animation_plus/issues +documentation: https://github.com/VMichael1999/polyline_animation_plus environment: - sdk: ^3.7.0 - flutter: ">=1.17.0" + sdk: ">=3.4.0 <4.0.0" + flutter: ">=3.22.0" dependencies: flutter: sdk: flutter - google_maps_flutter_platform_interface: ^2.14.0 + google_maps_flutter_platform_interface: ^2.10.0 dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^5.0.0 - + flutter_lints: ^4.0.0 + flutter: uses-material-design: true +platforms: + android: + ios: + web: + topics: - map-animation - animated-polylines diff --git a/test/animator/animator_equality_test.dart b/test/animator/animator_equality_test.dart index c1bfdde..ab9efb7 100644 --- a/test/animator/animator_equality_test.dart +++ b/test/animator/animator_equality_test.dart @@ -1,3 +1,6 @@ +// Non-const instances on purpose: equality must not depend on identity. +// ignore_for_file: prefer_const_constructors + import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:polyline_animation_plus/polyline_animation_plus.dart'; diff --git a/test/controllers/marker_controller_test.dart b/test/controllers/marker_controller_test.dart index 012743c..5a931b4 100644 --- a/test/controllers/marker_controller_test.dart +++ b/test/controllers/marker_controller_test.dart @@ -11,11 +11,12 @@ MarkerController _controller( AnimationController animation, Marker marker, { bool useMarkerRotation = false, -}) => MarkerController( - marker: marker, - animationController: animation, - useMarkerRotation: useMarkerRotation, -); +}) => + MarkerController( + marker: marker, + animationController: animation, + useMarkerRotation: useMarkerRotation, + ); void main() { late AnimationController animation; From b11e3adc8b2ae4f7d0b5e994bd960480d01dde3b Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:38:22 -0500 Subject: [PATCH 12/27] Apply dart format for language version 3.4 Formatting only, no behavior change. --- .../animations/delayed_curved_animation.dart | 29 +++++++++---------- lib/src/animator/base/polyline_animator.dart | 16 +++++----- lib/src/controllers/marker_controller.dart | 6 ++-- lib/src/controllers/polyline_controller.dart | 10 +++---- lib/src/managers/animated_marker_manager.dart | 16 +++++----- .../managers/animated_polyline_manager.dart | 4 +-- lib/src/tween/bearing_tween.dart | 2 +- lib/src/tween/location_tween.dart | 2 +- lib/src/utils/spherical_util.dart | 13 ++++----- 9 files changed, 46 insertions(+), 52 deletions(-) diff --git a/lib/src/animations/delayed_curved_animation.dart b/lib/src/animations/delayed_curved_animation.dart index 332b787..9b26fcb 100644 --- a/lib/src/animations/delayed_curved_animation.dart +++ b/lib/src/animations/delayed_curved_animation.dart @@ -18,21 +18,20 @@ class DelayedCurvedAnimation extends CurvedAnimation { this.delayStart = Duration.zero, this.delayEnd = Duration.zero, Curve curve = Curves.linear, - }) : animationDuration = Duration( - microseconds: - totalDuration.inMicroseconds - - delayStart.inMicroseconds - - delayEnd.inMicroseconds, - ), - super( - parent: controller, - curve: _calculateAnimationInterval( - totalDuration, - delayStart, - delayEnd, - curve, - ), - ); + }) : animationDuration = Duration( + microseconds: totalDuration.inMicroseconds - + delayStart.inMicroseconds - + delayEnd.inMicroseconds, + ), + super( + parent: controller, + curve: _calculateAnimationInterval( + totalDuration, + delayStart, + delayEnd, + curve, + ), + ); static Interval _calculateAnimationInterval( Duration totalDuration, diff --git a/lib/src/animator/base/polyline_animator.dart b/lib/src/animator/base/polyline_animator.dart index 86339ec..e936cdc 100644 --- a/lib/src/animator/base/polyline_animator.dart +++ b/lib/src/animator/base/polyline_animator.dart @@ -64,14 +64,14 @@ abstract class PolylineAnimator { @override int get hashCode => Object.hash( - duration, - curve, - repeat, - repeatCount, - reverse, - delayStart, - delayEnd, - ); + duration, + curve, + repeat, + repeatCount, + reverse, + delayStart, + delayEnd, + ); @override String toString() { diff --git a/lib/src/controllers/marker_controller.dart b/lib/src/controllers/marker_controller.dart index ce2c0fe..10c0bc9 100644 --- a/lib/src/controllers/marker_controller.dart +++ b/lib/src/controllers/marker_controller.dart @@ -36,8 +36,8 @@ class MarkerController { required Marker marker, required AnimationController animationController, this.useMarkerRotation = false, - }) : _currentMarker = marker, - _animationController = animationController { + }) : _currentMarker = marker, + _animationController = animationController { _locationTween = LocationTween( begin: marker.position, end: marker.position, @@ -66,7 +66,7 @@ class MarkerController { void _setupTo(Marker m) { final moved = SphericalUtil.computeDistanceBetween(_locationTween.end, m.position) >= - minMoveMeters; + minMoveMeters; _currentMarker = m; _locationTween.swap(m.position); diff --git a/lib/src/controllers/polyline_controller.dart b/lib/src/controllers/polyline_controller.dart index b91c750..49dfe8e 100644 --- a/lib/src/controllers/polyline_controller.dart +++ b/lib/src/controllers/polyline_controller.dart @@ -36,15 +36,13 @@ class PolylineAnimationController { void _initialize() { // The controller must run for the whole cycle (delays included), because // DelayedCurvedAnimation computes its interval over that total. - final totalDuration = - polylineAnimator.duration + + final totalDuration = polylineAnimator.duration + polylineAnimator.delayStart + polylineAnimator.delayEnd; - _controller = - AnimationController(vsync: vsync, duration: totalDuration) - ..addListener(_listener) - ..addStatusListener(_statusListener); + _controller = AnimationController(vsync: vsync, duration: totalDuration) + ..addListener(_listener) + ..addStatusListener(_statusListener); if (polylineAnimator.delayStart != Duration.zero || polylineAnimator.delayEnd != Duration.zero) { diff --git a/lib/src/managers/animated_marker_manager.dart b/lib/src/managers/animated_marker_manager.dart index ff315dc..9f6ae79 100644 --- a/lib/src/managers/animated_marker_manager.dart +++ b/lib/src/managers/animated_marker_manager.dart @@ -18,10 +18,9 @@ class AnimatedMarkersManager { // 16.67 ms per frame for 60 FPS (1000 ms / 60 FPS) ~= 16.67 ms totalFrames = (duration.inMilliseconds / 16.67).round(); - _animationController = - AnimationController(vsync: vsync, duration: duration) - ..addStatusListener(_statusListener) - ..addListener(listener); + _animationController = AnimationController(vsync: vsync, duration: duration) + ..addStatusListener(_statusListener) + ..addListener(listener); } late final int totalFrames; @@ -43,11 +42,10 @@ class AnimatedMarkersManager { void push(Set markers) { for (var marker in markers) { - final controller = - _controllers[marker.markerId] ??= MarkerController( - marker: marker, - animationController: _animationController, - ); + final controller = _controllers[marker.markerId] ??= MarkerController( + marker: marker, + animationController: _animationController, + ); controller.pushToQueue(marker); } diff --git a/lib/src/managers/animated_polyline_manager.dart b/lib/src/managers/animated_polyline_manager.dart index f82f886..3288424 100644 --- a/lib/src/managers/animated_polyline_manager.dart +++ b/lib/src/managers/animated_polyline_manager.dart @@ -26,8 +26,8 @@ class AnimatedPolylineManager { AnimatedPolylineManager({ required TickerProvider vsync, required PolylineListener polylineListener, - }) : _vsync = vsync, - _listener = polylineListener; + }) : _vsync = vsync, + _listener = polylineListener; List get activePolylineIds => _controllers.keys.toList(); diff --git a/lib/src/tween/bearing_tween.dart b/lib/src/tween/bearing_tween.dart index bff2057..c37f4a0 100644 --- a/lib/src/tween/bearing_tween.dart +++ b/lib/src/tween/bearing_tween.dart @@ -8,7 +8,7 @@ import '../utils/spherical_util.dart'; class BearingTween extends Tween { BearingTween({required double begin, required double end}) - : super(begin: begin, end: end); + : super(begin: begin, end: end); @override double get begin => super.begin!; diff --git a/lib/src/tween/location_tween.dart b/lib/src/tween/location_tween.dart index 1f4fad0..90d0fa2 100644 --- a/lib/src/tween/location_tween.dart +++ b/lib/src/tween/location_tween.dart @@ -9,7 +9,7 @@ import '../utils/spherical_util.dart'; class LocationTween extends Tween { LocationTween({required LatLng begin, required LatLng end}) - : super(begin: begin, end: end); + : super(begin: begin, end: end); @override LatLng get begin => super.begin!; diff --git a/lib/src/utils/spherical_util.dart b/lib/src/utils/spherical_util.dart index ba192f2..f7de6c7 100644 --- a/lib/src/utils/spherical_util.dart +++ b/lib/src/utils/spherical_util.dart @@ -95,8 +95,7 @@ class SphericalUtil { // No solution which would make sense in LatLng-space. return null; } - final fromLngRadians = - MathUtil.toRadians(to.longitude) - + final fromLngRadians = MathUtil.toRadians(to.longitude) - atan2(n3, n1 * cos(fromLatRadians) - n2 * sin(fromLatRadians)); return LatLng( MathUtil.toDegrees(fromLatRadians).toDouble(), @@ -153,11 +152,11 @@ class SphericalUtil { /// Returns the angle between two LatLngs, in radians. This is the same as the /// distance on the unit sphere. static num computeAngleBetween(LatLng from, LatLng to) => distanceRadians( - MathUtil.toRadians(from.latitude), - MathUtil.toRadians(from.longitude), - MathUtil.toRadians(to.latitude), - MathUtil.toRadians(to.longitude), - ); + MathUtil.toRadians(from.latitude), + MathUtil.toRadians(from.longitude), + MathUtil.toRadians(to.latitude), + MathUtil.toRadians(to.longitude), + ); /// Returns the distance between two LatLngs, in meters. static num computeDistanceBetween(LatLng from, LatLng to) => From cb693f81e6971da7a157d0c7f866a39abf1eff54 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:38:34 -0500 Subject: [PATCH 13/27] Remove deprecated legacy Android renderer from the example The legacy renderer is no longer supported by Google Maps and requesting it has no effect, so the initialization block is gone. This also drops two imports of packages the example did not declare. --- example/lib/main.dart | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 364683d..f219b31 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,25 +1,10 @@ import 'package:flutter/material.dart'; import 'package:polyline_animation_plus/polyline_animation_plus.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; -// ignore: depend_on_referenced_packages -import 'package:google_maps_flutter_android/google_maps_flutter_android.dart'; -import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'data.dart'; -void main() async { - final GoogleMapsFlutterPlatform mapsImplementation = - GoogleMapsFlutterPlatform.instance; - try { - if (mapsImplementation is GoogleMapsFlutterAndroid) { - WidgetsFlutterBinding.ensureInitialized(); - await mapsImplementation.initializeWithRenderer( - AndroidMapRenderer.legacy, - ); - } - } catch (e) { - debugPrint('Error initializing Google Maps: $e'); - } +void main() { runApp(const MyApp()); } From 4a8f5862bfa4fe233d5626b147da82b9e1def526 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:38:57 -0500 Subject: [PATCH 14/27] Add CHANGELOG entry for 1.1.0 --- CHANGELOG.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79f1c44..ab41412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,31 @@ +## 1.1.0 (unreleased) + +### Breaking behavior + +- Animations with `delayStart`/`delayEnd` now take the full `duration` to draw. Before, the delays were taken out of `duration`, so the drawing phase was shorter than configured. If you shortened `duration` to compensate, restore the value you intended. +- `MapAnimationUtils.generateEquidistantPolylineByDuration` now returns evenly spaced points, no duplicated first point and including the last point of the path. The number and position of the generated points changed. +- A marker that does not move (less than 0.5 m) keeps its rotation instead of turning to face north. + +### New + +- `MapAnimationController.useMarkerRotation` (default `false`): use `Marker.rotation` instead of the heading between positions. +- `SnackAnimator` accepts `delayStart` and `delayEnd`. +- `ColorTransitionAnimation` accepts `repeatCount`, `reverse`, `delayStart` and `delayEnd`. + +### Fixes + +- `PolylineAnimator` equality and `hashCode` now include `delayStart` and `delayEnd`, and `ColorTransitionAnimation` includes `colors`. Changing only those values now restarts the animation. +- `generateEquidistantPolylineByDuration` no longer loops forever when the path has zero length. + +### Other + +- Supports Flutter 3.22 and Dart 3.4 (was effectively Flutter 3.27): `Color.withValues` replaced with `withAlpha`, `google_maps_flutter_platform_interface` constraint lowered to `^2.10.0`. +- Declared supported platforms: Android, iOS and web. +- `onAnimationStop` is documented: called once when the animation completes, not on dispose and not for endless repeating animations. +- Added unit tests. +- Repository links point to `VMichael1999`. +- Example no longer requests the deprecated legacy Android renderer. + ## 1.0.4 - Initial release of `polyline_animation_plus`. From 02a46a48cc3eaffc87c600ebaa0c2847413d809b Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:40:24 -0500 Subject: [PATCH 15/27] Add tests for MapAnimationController with a fake maps platform FakeMapsPlatform records marker and polyline updates so tests can check what a real map would show: initial state, animated polylines, marker movement and deferred removal, static polyline updates and dispose. --- example/pubspec.lock | 2 +- pubspec.yaml | 1 + .../map_animation_controller_test.dart | 242 ++++++++++++++++++ test/fakes/fake_maps_platform.dart | 46 ++++ 4 files changed, 290 insertions(+), 1 deletion(-) create mode 100644 test/controllers/map_animation_controller_test.dart create mode 100644 test/fakes/fake_maps_platform.dart diff --git a/example/pubspec.lock b/example/pubspec.lock index a32c735..d39a315 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -222,7 +222,7 @@ packages: path: ".." relative: true source: path - version: "0.0.1" + version: "1.0.4" sanitize_html: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d80a803..9ad5763 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,6 +18,7 @@ dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^4.0.0 + plugin_platform_interface: ^2.1.7 flutter: uses-material-design: true diff --git a/test/controllers/map_animation_controller_test.dart b/test/controllers/map_animation_controller_test.dart new file mode 100644 index 0000000..113d3e8 --- /dev/null +++ b/test/controllers/map_animation_controller_test.dart @@ -0,0 +1,242 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; + +import '../fakes/fake_maps_platform.dart'; + +const _mapId = 7; +const _a = MarkerId('a'); +const _b = MarkerId('b'); +const _p1 = PolylineId('p1'); +const _p2 = PolylineId('p2'); + +const _path = [LatLng(0, 0), LatLng(0, 1), LatLng(0, 2), LatLng(0, 3)]; + +Polyline _line(PolylineId id) => + Polyline(polylineId: id, color: Colors.blue, points: _path); + +Marker _marker(MarkerId id, LatLng position) => + Marker(markerId: id, position: position); + +void main() { + late FakeMapsPlatform platform; + + setUp(() { + platform = FakeMapsPlatform(); + GoogleMapsFlutterPlatform.instance = platform; + }); + + MapAnimationController create( + WidgetTester tester, { + Set markers = const {}, + Set polylines = const {}, + MarkerListener? markerListener, + }) => + MapAnimationController( + mapId: _mapId, + vsync: tester, + markers: markers, + polylines: polylines, + markerListener: markerListener, + ); + + group('initial state', () { + testWidgets('sends markers and static polylines to the map', ( + tester, + ) async { + final controller = create( + tester, + markers: {_marker(_a, const LatLng(1, 1))}, + polylines: {AnimatedPolyline(polyline: _line(_p1))}, + ); + + expect(platform.markers.keys, [_a]); + expect(platform.polylines.keys, [_p1]); + expect(platform.mapIds, {_mapId}); + controller.dispose(); + }); + + testWidgets('draws an animated polyline frame by frame', (tester) async { + final controller = create( + tester, + polylines: { + AnimatedPolyline( + polyline: _line(_p1), + polylineAnimator: const SnackAnimator( + duration: Duration(seconds: 2), + curve: Curves.linear, + ), + ), + }, + ); + expect(platform.polylines, isEmpty); + + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + expect(platform.polylines[_p1]!.points, hasLength(2)); + + await tester.pump(const Duration(milliseconds: 500)); + expect(platform.polylines[_p1]!.points, hasLength(4)); + controller.dispose(); + }); + }); + + group('markers', () { + testWidgets('a new marker appears immediately', (tester) async { + final controller = create(tester); + controller.updateMarkers({_marker(_a, const LatLng(1, 1))}); + + expect(platform.markers[_a]!.position, const LatLng(1, 1)); + controller.dispose(); + }); + + testWidgets('moves a marker smoothly to its new position', (tester) async { + final updates = >[]; + final controller = create( + tester, + markers: {_marker(_a, const LatLng(0, 0))}, + markerListener: updates.add, + ); + + controller.updateMarkers({_marker(_a, const LatLng(0, 1))}); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); + + final midway = platform.markers[_a]!.position; + expect(midway.longitude, inInclusiveRange(0.4, 0.6)); + expect(updates, isNotEmpty); + + await tester.pump(const Duration(seconds: 1)); + expect(platform.markers[_a]!.position.longitude, closeTo(1, 1e-9)); + controller.dispose(); + }); + + testWidgets('removes markers that are no longer present', (tester) async { + final controller = create( + tester, + markers: { + _marker(_a, const LatLng(0, 0)), + _marker(_b, const LatLng(1, 1)), + }, + ); + + controller.updateMarkers({_marker(_a, const LatLng(0, 0))}); + + expect(platform.markers.keys, [_a]); + controller.dispose(); + }); + + testWidgets('defers removal while an animation is running', ( + tester, + ) async { + final controller = create( + tester, + markers: { + _marker(_a, const LatLng(0, 0)), + _marker(_b, const LatLng(1, 1)), + }, + ); + + controller.updateMarkers({ + _marker(_a, const LatLng(0, 1)), + _marker(_b, const LatLng(1, 1)), + }); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + + // b is removed while the animation is running. + controller.updateMarkers({_marker(_a, const LatLng(0, 1))}); + expect(platform.markers.keys, containsAll([_a, _b])); + + await tester.pump(const Duration(seconds: 2)); + expect(platform.markers.keys, [_a]); + controller.dispose(); + }); + }); + + group('polylines', () { + testWidgets('updates a static polyline directly', (tester) async { + final controller = create(tester); + controller.updatePolylines({AnimatedPolyline(polyline: _line(_p1))}); + + expect(platform.polylines.keys, [_p1]); + controller.dispose(); + }); + + testWidgets('removes polylines that are no longer present', (tester) async { + final controller = create( + tester, + polylines: { + AnimatedPolyline(polyline: _line(_p1)), + AnimatedPolyline(polyline: _line(_p2)), + }, + ); + + controller.updatePolylines({AnimatedPolyline(polyline: _line(_p1))}); + + expect(platform.polylines.keys, [_p1]); + controller.dispose(); + }); + + testWidgets('stops animating a polyline that becomes static', ( + tester, + ) async { + final controller = create( + tester, + polylines: { + AnimatedPolyline( + polyline: _line(_p1), + polylineAnimator: const SnackAnimator( + duration: Duration(seconds: 2), + repeat: true, + ), + ), + }, + ); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + + controller.updatePolylines({AnimatedPolyline(polyline: _line(_p1))}); + final callsAfterSwitch = platform.polylineUpdateCalls; + await tester.pump(const Duration(seconds: 1)); + + expect(platform.polylineUpdateCalls, callsAfterSwitch); + expect(platform.polylines[_p1]!.points, _path); + controller.dispose(); + }); + + testWidgets('updateStaticPolyline draws the given polyline', ( + tester, + ) async { + final controller = create(tester); + controller.updateStaticPolyline(_line(_p2)); + + expect(platform.polylines.keys, [_p2]); + controller.dispose(); + }); + }); + + testWidgets('dispose stops all updates', (tester) async { + final controller = create( + tester, + polylines: { + AnimatedPolyline( + polyline: _line(_p1), + polylineAnimator: const SnackAnimator( + duration: Duration(seconds: 2), + repeat: true, + ), + ), + }, + ); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 500)); + + controller.dispose(); + final calls = platform.polylineUpdateCalls; + await tester.pump(const Duration(seconds: 1)); + + expect(platform.polylineUpdateCalls, calls); + }); +} diff --git a/test/fakes/fake_maps_platform.dart b/test/fakes/fake_maps_platform.dart new file mode 100644 index 0000000..8c6dc64 --- /dev/null +++ b/test/fakes/fake_maps_platform.dart @@ -0,0 +1,46 @@ +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +/// A [GoogleMapsFlutterPlatform] that records what the package draws. +/// +/// [markers] and [polylines] hold what a real map would currently show, and +/// the counters tell how many updates were sent. +class FakeMapsPlatform extends GoogleMapsFlutterPlatform + with MockPlatformInterfaceMixin { + final markers = {}; + final polylines = {}; + + int markerUpdateCalls = 0; + int polylineUpdateCalls = 0; + final mapIds = {}; + + @override + Future updateMarkers(MarkerUpdates markerUpdates, + {required int mapId}) async { + markerUpdateCalls++; + mapIds.add(mapId); + for (final m in markerUpdates.markersToAdd) { + markers[m.markerId] = m; + } + for (final m in markerUpdates.markersToChange) { + markers[m.markerId] = m; + } + markerUpdates.markerIdsToRemove.forEach(markers.remove); + } + + @override + Future updatePolylines( + PolylineUpdates polylineUpdates, { + required int mapId, + }) async { + polylineUpdateCalls++; + mapIds.add(mapId); + for (final p in polylineUpdates.polylinesToAdd) { + polylines[p.polylineId] = p; + } + for (final p in polylineUpdates.polylinesToChange) { + polylines[p.polylineId] = p; + } + polylineUpdates.polylineIdsToRemove.forEach(polylines.remove); + } +} From abcca91f6ba746fb37d6df51552d971e41cf3c12 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:41:28 -0500 Subject: [PATCH 16/27] Add tests for SphericalUtil, MathUtil, animators and AnimatedPolyline --- test/animator/animators_test.dart | 76 +++++++++++++++ test/model/animated_polyline_test.dart | 27 ++++++ test/utils/spherical_util_test.dart | 126 +++++++++++++++++++++++++ 3 files changed, 229 insertions(+) create mode 100644 test/animator/animators_test.dart create mode 100644 test/model/animated_polyline_test.dart create mode 100644 test/utils/spherical_util_test.dart diff --git a/test/animator/animators_test.dart b/test/animator/animators_test.dart new file mode 100644 index 0000000..258067d --- /dev/null +++ b/test/animator/animators_test.dart @@ -0,0 +1,76 @@ +// `Color.value` is deprecated on new Flutter but is the only way to compare +// colors on the minimum supported version. +// ignore_for_file: deprecated_member_use + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; + +const _polyline = Polyline( + polylineId: PolylineId('p'), + color: Colors.black, + points: [LatLng(0, 0), LatLng(0, 1), LatLng(0, 2), LatLng(0, 3)], +); + +void main() { + group('SnackAnimator', () { + const animator = SnackAnimator(); + + test('draws the line during the first half', () { + expect(animator.animate(_polyline, 0).points, isEmpty); + expect( + animator.animate(_polyline, 0.25).points, _polyline.points.take(2)); + expect(animator.animate(_polyline, 0.5).points, _polyline.points); + }); + + test('erases the line from the start during the second half', () { + expect( + animator.animate(_polyline, 0.75).points, _polyline.points.skip(2)); + expect(animator.animate(_polyline, 1).points, isEmpty); + }); + }); + + group('ColorTransitionAnimation', () { + const animator = ColorTransitionAnimation( + colors: [Colors.red, Colors.blue], + ); + + test('starts with the first color', () { + expect(animator.animate(_polyline, 0).color.value, Colors.red.value); + }); + + test('reaches the next color halfway', () { + expect(animator.animate(_polyline, 0.5).color.value, Colors.blue.value); + }); + + test('blends the colors in between', () { + expect( + animator.animate(_polyline, 0.25).color.value, + Color.lerp(Colors.red, Colors.blue, 0.5)!.value, + ); + }); + + test('keeps the points untouched', () { + expect(animator.animate(_polyline, 0.3).points, _polyline.points); + }); + }); + + group('PolylineAnimator', () { + test('equality is false for another type or other settings', () { + const fade = FadeInProgressiveAnimator(); + expect(fade == const SnackAnimator(), isFalse); + expect( + fade == const FadeInProgressiveAnimator(repeatCount: 2), + isFalse, + ); + expect(fade == const FadeInProgressiveAnimator(reverse: true), isFalse); + }); + + test('toString lists the settings', () { + final text = const SnackAnimator(repeatCount: 2).toString(); + expect(text, contains('repeatCount: 2')); + expect(text, contains('delayStart')); + }); + }); +} diff --git a/test/model/animated_polyline_test.dart b/test/model/animated_polyline_test.dart new file mode 100644 index 0000000..3880c53 --- /dev/null +++ b/test/model/animated_polyline_test.dart @@ -0,0 +1,27 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; + +void main() { + const line = Polyline(polylineId: PolylineId('p')); + + test('equal when polyline and animator are equal', () { + const a = + AnimatedPolyline(polyline: line, polylineAnimator: SnackAnimator()); + const b = + AnimatedPolyline(polyline: line, polylineAnimator: SnackAnimator()); + expect(a, b); + expect(a.hashCode, b.hashCode); + }); + + test('different animators make them different', () { + const a = + AnimatedPolyline(polyline: line, polylineAnimator: SnackAnimator()); + const b = AnimatedPolyline(polyline: line); + expect(a, isNot(b)); + }); + + test('toString mentions the polyline', () { + expect(const AnimatedPolyline(polyline: line).toString(), contains('p')); + }); +} diff --git a/test/utils/spherical_util_test.dart b/test/utils/spherical_util_test.dart new file mode 100644 index 0000000..e0eda5e --- /dev/null +++ b/test/utils/spherical_util_test.dart @@ -0,0 +1,126 @@ +import 'dart:math'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/src/utils/math_util.dart'; +import 'package:polyline_animation_plus/src/utils/spherical_util.dart'; + +const _origin = LatLng(0, 0); +final _quarterCircle = SphericalUtil.earthRadius * pi / 2; + +void expectLatLng(LatLng actual, LatLng expected, {double tolerance = 1e-6}) { + expect(actual.latitude, closeTo(expected.latitude, tolerance)); + expect(actual.longitude, closeTo(expected.longitude, tolerance)); +} + +void main() { + group('SphericalUtil', () { + test('computeHeading follows the compass', () { + expect(SphericalUtil.computeHeading(_origin, const LatLng(1, 0)), 0); + expect( + SphericalUtil.computeHeading(_origin, const LatLng(0, 1)), + closeTo(90, 1e-9), + ); + expect( + SphericalUtil.computeHeading(_origin, const LatLng(-1, 0)), + closeTo(-180, 1e-9), + ); + expect( + SphericalUtil.computeHeading(_origin, const LatLng(0, -1)), + closeTo(-90, 1e-9), + ); + }); + + test('computeOffset moves a quarter of the Earth along the equator', () { + final result = SphericalUtil.computeOffset(_origin, _quarterCircle, 90); + expectLatLng(result, const LatLng(0, 90)); + }); + + test('computeOffsetOrigin undoes computeOffset', () { + final distance = SphericalUtil.earthRadius * pi / 4; + final destination = SphericalUtil.computeOffset(_origin, distance, 90); + final origin = + SphericalUtil.computeOffsetOrigin(destination, distance, 90); + expectLatLng(origin!, _origin); + }); + + test('computeOffsetOrigin returns null when there is no solution', () { + final origin = SphericalUtil.computeOffsetOrigin( + const LatLng(80, 0), + SphericalUtil.earthRadius * 20 * pi / 180, + 90, + ); + expect(origin, isNull); + }); + + test('interpolate returns the middle point', () { + expectLatLng( + SphericalUtil.interpolate(_origin, const LatLng(0, 90), 0.5), + const LatLng(0, 45), + ); + }); + + test('interpolate between identical points returns that point', () { + expectLatLng( + SphericalUtil.interpolate(const LatLng(3, 4), const LatLng(3, 4), 0.5), + const LatLng(3, 4), + ); + }); + + test('distance and length are measured on the sphere', () { + const end = LatLng(0, 90); + expect( + SphericalUtil.computeDistanceBetween(_origin, end), + closeTo(_quarterCircle, 1e-3), + ); + expect( + SphericalUtil.computeLength([_origin, const LatLng(0, 45), end]), + closeTo(_quarterCircle, 1e-3), + ); + expect(SphericalUtil.computeLength([_origin]), 0); + }); + + test('computeArea of an octant of the Earth', () { + const octant = [LatLng(0, 0), LatLng(0, 90), LatLng(90, 0)]; + final expected = pi * pow(SphericalUtil.earthRadius, 2) / 2; + + expect(SphericalUtil.computeArea(octant), closeTo(expected, 1)); + expect( + SphericalUtil.computeSignedArea(octant.reversed.toList()).abs(), + closeTo(expected, 1), + ); + expect(SphericalUtil.computeArea(const [_origin, LatLng(1, 1)]), 0); + }); + + test('angleLerp takes the shortest way around', () { + expect(SphericalUtil.angleLerp(0, 90, 0.5), closeTo(45, 1e-9)); + expect(SphericalUtil.angleLerp(350, 10, 0.5), closeTo(360, 1e-9)); + expect(SphericalUtil.angleLerp(10, 0, 1), 0); + expect(SphericalUtil.angleLerp(0, 0, 0.5), 0); + }); + }); + + group('MathUtil', () { + test('converts between degrees and radians', () { + expect(MathUtil.toRadians(180), closeTo(pi, 1e-12)); + expect(MathUtil.toDegrees(pi), closeTo(180, 1e-12)); + }); + + test('wrap keeps values inside [min, max)', () { + expect(MathUtil.wrap(190, -180, 180), -170); + expect(MathUtil.wrap(10, -180, 180), 10); + expect(MathUtil.wrap(180, -180, 180), -180); + }); + + test('mod is never negative', () { + expect(MathUtil.mod(-1, 3), 2); + expect(MathUtil.mod(7, 3), 1); + }); + + test('haversine helpers agree with each other', () { + expect(MathUtil.hav(pi), closeTo(1, 1e-12)); + expect(MathUtil.arcHav(MathUtil.hav(1.2)), closeTo(1.2, 1e-12)); + expect(MathUtil.havDistance(0, 0, 0), 0); + }); + }); +} From 36bf153ed130ce6d099cf3d543f07a15534406e4 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:41:52 -0500 Subject: [PATCH 17/27] Add tests for managers, tweens and DelayedCurvedAnimation Line coverage of lib/ is now 97.6%. --- .../delayed_curved_animation_test.dart | 78 +++++++++++++++ .../animated_polyline_manager_test.dart | 97 +++++++++++++++++++ test/tween/tweens_test.dart | 46 +++++++++ test/utils/spherical_util_test.dart | 4 +- 4 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 test/animations/delayed_curved_animation_test.dart create mode 100644 test/managers/animated_polyline_manager_test.dart create mode 100644 test/tween/tweens_test.dart diff --git a/test/animations/delayed_curved_animation_test.dart b/test/animations/delayed_curved_animation_test.dart new file mode 100644 index 0000000..536522e --- /dev/null +++ b/test/animations/delayed_curved_animation_test.dart @@ -0,0 +1,78 @@ +import 'package:flutter/animation.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:polyline_animation_plus/src/animations/delayed_curved_animation.dart'; + +void main() { + late AnimationController controller; + + setUp(() => controller = AnimationController(vsync: const TestVSync())); + tearDown(() => controller.dispose()); + + DelayedCurvedAnimation create({ + Duration delayStart = const Duration(seconds: 1), + Duration delayEnd = const Duration(seconds: 1), + }) => + DelayedCurvedAnimation( + controller: controller, + totalDuration: const Duration(seconds: 5), + delayStart: delayStart, + delayEnd: delayEnd, + ); + + test('exposes the duration of the animated part', () { + expect(create().animationDuration, const Duration(seconds: 3)); + }); + + test('rejects delays that leave no time to animate', () { + expect( + () => create( + delayStart: const Duration(seconds: 3), + delayEnd: const Duration(seconds: 2), + ), + throwsArgumentError, + ); + }); + + test('stays at 0 during the start delay and at 1 during the end delay', () { + final animation = create(); + + controller.value = 0.1; + expect(animation.value, 0); + expect(animation.isInStartDelay, isTrue); + expect(animation.isAnimating, isFalse); + + controller.value = 0.9; + expect(animation.value, 1); + expect(animation.isInEndDelay, isTrue); + expect(animation.isAnimating, isFalse); + }); + + test('maps the middle of the cycle to the middle of the animation', () { + final animation = create(); + controller.value = 0.5; + + expect(animation.value, closeTo(0.5, 1e-9)); + expect(animation.animationProgress, closeTo(0.5, 1e-9)); + expect(animation.isAnimating, isTrue); + }); + + test('animationProgress is 0 and 1 at the ends', () { + final animation = create(); + + controller.value = 0; + expect(animation.animationProgress, 0); + controller.value = 1; + expect(animation.animationProgress, 1); + }); + + test('without delays it behaves like the plain controller', () { + final animation = create( + delayStart: Duration.zero, + delayEnd: Duration.zero, + ); + controller.value = 0.3; + + expect(animation.value, closeTo(0.3, 1e-9)); + expect(animation.isInStartDelay, isFalse); + }); +} diff --git a/test/managers/animated_polyline_manager_test.dart b/test/managers/animated_polyline_manager_test.dart new file mode 100644 index 0000000..a48abd4 --- /dev/null +++ b/test/managers/animated_polyline_manager_test.dart @@ -0,0 +1,97 @@ +// `Color.value` is deprecated on new Flutter but is the only way to compare +// colors on the minimum supported version. +// ignore_for_file: deprecated_member_use + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; +import 'package:polyline_animation_plus/src/managers/animated_polyline_manager.dart'; + +const _id = PolylineId('p'); +const _other = PolylineId('q'); +const _polyline = Polyline( + polylineId: _id, + points: [LatLng(0, 0), LatLng(0, 1)], +); + +void main() { + testWidgets('keeps one controller per polyline and replaces it on change', ( + tester, + ) async { + final updates = []; + final manager = AnimatedPolylineManager( + vsync: tester, + polylineListener: updates.add, + ); + + manager.push( + polyline: _polyline, + polylineAnimator: const SnackAnimator(repeat: true), + ); + manager.push( + polyline: _polyline, + polylineAnimator: const SnackAnimator(repeat: true), + ); + expect(manager.activePolylineIds, [_id]); + + // A different animator replaces the running one. + manager.push( + polyline: _polyline, + polylineAnimator: const SnackAnimator( + repeat: true, + delayStart: Duration(seconds: 1), + ), + ); + expect(manager.activePolylineIds, [_id]); + + manager.dispose(); + expect(manager.activePolylineIds, isEmpty); + }); + + testWidgets('removes polylines one at a time or in bulk', (tester) async { + final manager = AnimatedPolylineManager( + vsync: tester, + polylineListener: (_) {}, + ); + const animator = SnackAnimator(repeat: true); + manager.push(polyline: _polyline, polylineAnimator: animator); + manager.push( + polyline: const Polyline(polylineId: _other), + polylineAnimator: animator, + ); + + manager.removePolyline(_other); + manager.removePolyline(const PolylineId('missing')); + expect(manager.activePolylineIds, [_id]); + + manager.removePolylines({_id}); + expect(manager.activePolylineIds, isEmpty); + manager.dispose(); + }); + + testWidgets('a pushed polyline update is used by the running animation', ( + tester, + ) async { + final updates = []; + final manager = AnimatedPolylineManager( + vsync: tester, + polylineListener: updates.add, + ); + const animator = SnackAnimator( + duration: Duration(seconds: 2), + curve: Curves.linear, + ); + manager.push(polyline: _polyline, polylineAnimator: animator); + await tester.pump(); + + manager.push( + polyline: _polyline.copyWith(colorParam: Colors.red), + polylineAnimator: animator, + ); + await tester.pump(const Duration(milliseconds: 500)); + + expect(updates.last.color.value, Colors.red.value); + manager.dispose(); + }); +} diff --git a/test/tween/tweens_test.dart b/test/tween/tweens_test.dart new file mode 100644 index 0000000..278a38d --- /dev/null +++ b/test/tween/tweens_test.dart @@ -0,0 +1,46 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; +import 'package:polyline_animation_plus/src/tween/bearing_tween.dart'; +import 'package:polyline_animation_plus/src/tween/location_tween.dart'; + +void main() { + group('BearingTween', () { + test('returns the ends exactly', () { + final tween = BearingTween(begin: 10, end: 80); + expect(tween.lerp(0), 10); + expect(tween.lerp(1), 80); + }); + + test('turns the short way and transform matches lerp', () { + final tween = BearingTween(begin: 350, end: 10); + expect(tween.lerp(0.5), closeTo(360, 1e-9)); + expect(tween.transform(0.5), tween.lerp(0.5)); + }); + + test('swap continues from the previous end', () { + final tween = BearingTween(begin: 0, end: 90)..swap(180); + expect(tween.begin, 90); + expect(tween.end, 180); + }); + }); + + group('LocationTween', () { + test('interpolates over the sphere and exposes the bearing', () { + final tween = LocationTween( + begin: const LatLng(0, 0), + end: const LatLng(0, 2), + ); + expect(tween.lerp(0.5).longitude, closeTo(1, 1e-9)); + expect(tween.bearing, closeTo(90, 1e-9)); + }); + + test('swap continues from the previous end', () { + final tween = LocationTween( + begin: const LatLng(0, 0), + end: const LatLng(0, 1), + )..swap(const LatLng(1, 1)); + expect(tween.begin, const LatLng(0, 1)); + expect(tween.end, const LatLng(1, 1)); + }); + }); +} diff --git a/test/utils/spherical_util_test.dart b/test/utils/spherical_util_test.dart index e0eda5e..04eb994 100644 --- a/test/utils/spherical_util_test.dart +++ b/test/utils/spherical_util_test.dart @@ -6,7 +6,7 @@ import 'package:polyline_animation_plus/src/utils/math_util.dart'; import 'package:polyline_animation_plus/src/utils/spherical_util.dart'; const _origin = LatLng(0, 0); -final _quarterCircle = SphericalUtil.earthRadius * pi / 2; +const _quarterCircle = SphericalUtil.earthRadius * pi / 2; void expectLatLng(LatLng actual, LatLng expected, {double tolerance = 1e-6}) { expect(actual.latitude, closeTo(expected.latitude, tolerance)); @@ -37,7 +37,7 @@ void main() { }); test('computeOffsetOrigin undoes computeOffset', () { - final distance = SphericalUtil.earthRadius * pi / 4; + const distance = SphericalUtil.earthRadius * pi / 4; final destination = SphericalUtil.computeOffset(_origin, distance, 90); final origin = SphericalUtil.computeOffsetOrigin(destination, distance, 90); From a4fb457e428f75b6684a4141c9653a57d93e5c84 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:41:58 -0500 Subject: [PATCH 18/27] Ignore coverage output --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index eb1c2df..2af5682 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ build/ # Ensure demo asset is included in package !doc/demo.gif + +# Coverage +coverage/ From 90481bf284c93bc3c6355277e217761102b289a0 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:42:31 -0500 Subject: [PATCH 19/27] Add GitHub Actions CI and .pubignore Jobs: format/analyze/test with a 90% coverage gate and Codecov upload; Flutter 3.22.0 and stable against minimum and latest dependencies; publish dry run; Android debug build of the example. The demo GIF (7 MB) is left out of the published package. --- .github/workflows/ci.yml | 103 +++++++++++++++++++++++++++++++++++++++ .pubignore | 26 ++++++++++ 2 files changed, 129 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .pubignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..512d621 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,103 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + checks: + name: Format, analyze and test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + - run: flutter pub get + - name: Format + run: dart format --set-exit-if-changed lib test + - name: Analyze + run: flutter analyze + - name: Test with coverage + run: flutter test --coverage + - name: Check coverage is at least 90% + run: | + python3 - <<'PY' + found = hit = 0 + for line in open("coverage/lcov.info"): + if line.startswith("LF:"): + found += int(line[3:]) + elif line.startswith("LH:"): + hit += int(line[3:]) + percent = 100 * hit / found + print(f"line coverage: {percent:.1f}% ({hit}/{found})") + raise SystemExit(0 if percent >= 90 else "coverage below 90%") + PY + - uses: codecov/codecov-action@v4 + with: + files: coverage/lcov.info + token: ${{ secrets.CODECOV_TOKEN }} + fail_ci_if_error: false + + compatibility: + name: Flutter ${{ matrix.flutter }} / ${{ matrix.deps }} dependencies + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + flutter: ['3.22.0', 'stable'] + deps: [minimum, latest] + steps: + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ matrix.flutter != 'stable' && matrix.flutter || '' }} + channel: stable + cache: true + - name: Resolve dependencies + run: | + if [ "${{ matrix.deps }}" = "minimum" ]; then + flutter pub downgrade + else + flutter pub upgrade + fi + # The example needs a newer SDK than the package, so only lib and test + # are analyzed here. + - run: flutter analyze lib test + - run: flutter test + + publish-dry-run: + name: Publish dry run + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + - run: flutter pub get + - run: flutter pub publish --dry-run + + example-android: + name: Build example (Android) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: '17' + - uses: subosito/flutter-action@v2 + with: + channel: stable + cache: true + - run: flutter pub get + working-directory: example + - run: flutter build apk --debug + working-directory: example diff --git a/.pubignore b/.pubignore new file mode 100644 index 0000000..24fa692 --- /dev/null +++ b/.pubignore @@ -0,0 +1,26 @@ +# When this file exists pub ignores .gitignore, so the rules are repeated here. +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ +*.iml +*.ipr +*.iws +.idea/ +/pubspec.lock +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +build/ +coverage/ + +# Not part of the package: the demo is linked from the README on GitHub. +doc/demo.gif +doc/notes/ +.github/ From 34d506b26e3414eaa9562d201a4da9c7ec9356f3 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:42:41 -0500 Subject: [PATCH 20/27] Document animated markers and ID clashes in the README Also lists web as a supported platform and links the demo GIF by absolute URL because it is no longer part of the published package. --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b27842..99d9dd3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A Flutter package for creating smooth, customizable polyline animations on Googl ## 🎥 Demo

-Animated polyline drawing on Google Maps +Animated polyline drawing on Google Maps
This animation represents how the plugin behaves

@@ -19,7 +19,8 @@ This animation represents how the plugin behaves - 🎬 **Animated polylines** with progressive drawing effects - 🔁 **Repeatable** or one‑shot animations - ⏱️ **Custom duration**, delay, and animation curves -- 🗺️ Works on **Android & iOS** (Google Maps) +- 📍 **Animated markers** that glide between positions and turn towards the direction of travel +- 🗺️ Works on **Android, iOS and web** (Google Maps) - 🧩 Supports **multiple animated polylines** simultaneously - ⚡ Built using the `google_maps_flutter_platform_interface` @@ -94,10 +95,55 @@ onMapCreated(GoogleMapController controller) { } ``` +Remember to release the controller when the map goes away: + +```dart +@override +void dispose() { + mapAnimationController.dispose(); + super.dispose(); +} +``` + More complete examples can be found in the `/example` folder. --- +## 📍 Animated markers + +Pass the markers to the same controller and call `updateMarkers` every time a position changes (for example, on each GPS update). The marker glides from its previous position to the new one and rotates towards the direction of travel. + +```dart +mapAnimationController = MapAnimationController( + mapId: controller.mapId, + vsync: this, + markers: { + Marker(markerId: const MarkerId('driver'), position: start), + }, + // How long each move takes. Default: 2 seconds. + markersAnimationDuration: const Duration(seconds: 2), + // Called with the markers updated on every animation frame. + markerListener: (markers) {}, +); + +// When a new position arrives, send the full set of markers: +mapAnimationController.updateMarkers({ + Marker(markerId: const MarkerId('driver'), position: newPosition), +}); +``` + +- `updateMarkers` receives **all** the markers: the ones you leave out are removed from the map. +- Positions that arrive while a marker is still moving wait in a queue and are played in order. +- A marker that does not move keeps its rotation. Set `useMarkerRotation: true` to use `Marker.rotation` instead of the heading between positions. + +--- + +## ⚠️ Do not pass the same IDs to `GoogleMap` + +The controller draws directly on the map, using the `mapId`. If the `GoogleMap` widget also receives a polyline or marker with the same ID in its `polylines` or `markers`, the widget will overwrite what the controller draws. Give the controller its own IDs and leave them out of the widget's sets. + +--- + ## 📚 Additional Information - Issues and feature requests: **GitHub Issues** From 857e88ff855f4801791570cd0236c7e49d2901b1 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:43:41 -0500 Subject: [PATCH 21/27] Document the public API and enforce it with public_member_api_docs All exported classes, constructors, fields and methods now have dartdoc comments. The lint is enabled; internal files that are not exported opt out. --- analysis_options.yaml | 4 +++ .../animations/delayed_curved_animation.dart | 2 ++ lib/src/animator/base/polyline_animator.dart | 31 ++++++++++++++----- lib/src/animator/color_animator.dart | 6 ++++ .../fade_in_progressive_animator.dart | 3 ++ lib/src/animator/snack_animator.dart | 4 +++ .../controllers/map_animation_controller.dart | 24 ++++++++++++++ lib/src/controllers/marker_controller.dart | 2 ++ lib/src/controllers/polyline_controller.dart | 2 ++ lib/src/managers/animated_marker_manager.dart | 2 ++ .../managers/animated_polyline_manager.dart | 2 ++ lib/src/model/animated_polyline.dart | 6 +++- lib/src/tween/bearing_tween.dart | 2 ++ lib/src/tween/location_tween.dart | 2 ++ lib/src/utils/math_util.dart | 2 ++ lib/src/utils/spherical_util.dart | 2 ++ lib/src/utils/util.dart | 11 +++++-- 17 files changed, 97 insertions(+), 10 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index a5744c1..cf1dc8a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -2,3 +2,7 @@ include: package:flutter_lints/flutter.yaml # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options + +linter: + rules: + public_member_api_docs: true diff --git a/lib/src/animations/delayed_curved_animation.dart b/lib/src/animations/delayed_curved_animation.dart index 9b26fcb..2f3aefd 100644 --- a/lib/src/animations/delayed_curved_animation.dart +++ b/lib/src/animations/delayed_curved_animation.dart @@ -1,6 +1,8 @@ // Based on google_map_animation by Manish Relani (BSD-3-Clause). // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. +// Internal, not exported: public API docs are only required for exported code. +// ignore_for_file: public_member_api_docs import 'dart:math' as math; diff --git a/lib/src/animator/base/polyline_animator.dart b/lib/src/animator/base/polyline_animator.dart index e936cdc..c906605 100644 --- a/lib/src/animator/base/polyline_animator.dart +++ b/lib/src/animator/base/polyline_animator.dart @@ -5,25 +5,39 @@ import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; -/// This abstract class defines the properties needed to animate a polyline -/// on a Google Map +/// Describes how a polyline is animated on a Google Map. +/// +/// Extend it and implement [animate] to create your own animation. The +/// controller calls [animate] on every frame with the original polyline and +/// the current progress, and draws the polyline it returns. abstract class PolylineAnimator { + /// Time the animation takes to go from progress 0 to 1, without the delays. final Duration duration; + + /// Curve applied to the progress passed to [animate]. final Curve curve; + + /// Whether the animation starts again when it ends. final bool repeat; + + /// When repeating, whether the animation plays backwards on every other + /// cycle instead of jumping back to the start. final bool reverse; - /// Delay before the animation starts - /// This is usefull for repeating animations where you want to wait before starting the next cycle + /// Time to wait, with the progress at 0, before each cycle starts drawing. + /// + /// It is added to [duration], it does not shorten it. final Duration delayStart; - /// Delay after the animation ends - /// This is useful for repeating animations where you want to wait before starting the next cycle + /// Time to wait, with the progress at 1, after each cycle finishes drawing. + /// + /// It is added to [duration], it does not shorten it. final Duration delayEnd; - /// Number of times to repeat the animation (null means infinite) + /// Number of cycles to play when [repeat] is true. `null` means forever. final int? repeatCount; + /// Creates an animator. Subclasses pass their own defaults. const PolylineAnimator({ required this.duration, this.curve = Curves.linear, @@ -34,6 +48,9 @@ abstract class PolylineAnimator { this.delayEnd = Duration.zero, }); + /// Returns the polyline to draw for the given [progress], between 0 and 1. + /// + /// [polyline] is always the original polyline, not the previous frame. Polyline animate(Polyline polyline, double progress); /// Called once when the animation reaches its end. diff --git a/lib/src/animator/color_animator.dart b/lib/src/animator/color_animator.dart index aee2203..af9ead6 100644 --- a/lib/src/animator/color_animator.dart +++ b/lib/src/animator/color_animator.dart @@ -7,9 +7,15 @@ import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; +/// Changes the color of the polyline smoothly through [colors], one after +/// the other, and back to the first one. +/// +/// The points are not modified. [colors] must not be empty. class ColorTransitionAnimation extends PolylineAnimator { + /// Colors the polyline goes through, in order. final List colors; + /// Creates a color transition through [colors]. const ColorTransitionAnimation({ required this.colors, super.duration = const Duration(seconds: 5), diff --git a/lib/src/animator/fade_in_progressive_animator.dart b/lib/src/animator/fade_in_progressive_animator.dart index 1b54d6a..6f679b3 100644 --- a/lib/src/animator/fade_in_progressive_animator.dart +++ b/lib/src/animator/fade_in_progressive_animator.dart @@ -6,7 +6,10 @@ import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; +/// Fades the polyline in during the first 30% of the animation and then +/// erases it from its start to its end during the remaining 70%. class FadeInProgressiveAnimator extends PolylineAnimator { + /// Creates a fade-in animator that repeats by default. const FadeInProgressiveAnimator({ super.duration = const Duration(seconds: 5), super.curve = Curves.ease, diff --git a/lib/src/animator/snack_animator.dart b/lib/src/animator/snack_animator.dart index 3b13a0c..f4a6b36 100644 --- a/lib/src/animator/snack_animator.dart +++ b/lib/src/animator/snack_animator.dart @@ -6,7 +6,11 @@ import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; +/// Draws the polyline from its start to its end during the first half of the +/// animation and erases it in the same direction during the second half, like +/// a snake crossing the route. class SnackAnimator extends PolylineAnimator { + /// Creates a snake-like animator that plays once by default. const SnackAnimator({ super.duration = const Duration(seconds: 2), super.curve = Curves.easeInOut, diff --git a/lib/src/controllers/map_animation_controller.dart b/lib/src/controllers/map_animation_controller.dart index 3771609..4396885 100644 --- a/lib/src/controllers/map_animation_controller.dart +++ b/lib/src/controllers/map_animation_controller.dart @@ -9,14 +9,26 @@ import '../managers/animated_marker_manager.dart'; import '../managers/animated_polyline_manager.dart'; import '../model/animated_polyline.dart'; +/// Called with the polyline that was just drawn on the map. typedef PolylineListener = void Function(Polyline); + +/// Called with the markers that were just updated on the map. typedef MarkerListener = void Function(Set); +/// Animates polylines and markers on a Google Map. +/// +/// It draws directly on the map with the given [mapId], so the `GoogleMap` +/// widget must not receive polylines or markers with the same IDs. Call +/// [dispose] when the map goes away. final class MapAnimationController { + /// Drives the animations, usually the `State` of the map widget mixed with + /// `TickerProviderStateMixin`. final TickerProvider vsync; + /// Called every time animated markers are updated, once per frame. final MarkerListener? markerListener; + /// ID of the map to draw on, from `GoogleMapController.mapId`. final int mapId; /// Use [Marker.rotation] as the rotation of animated markers instead of the @@ -26,6 +38,10 @@ final class MapAnimationController { /// Duration for marker animation transitions. Default is 2 second. final Duration markersAnimationDuration; + /// Creates a controller and immediately draws [markers] and [polylines]. + /// + /// Polylines with a [AnimatedPolyline.polylineAnimator] are animated, the + /// others are drawn as they are. MapAnimationController({ required this.mapId, required this.vsync, @@ -94,6 +110,11 @@ final class MapAnimationController { _updatePolylinesOnMap({}, _polylines.values.toSet()); } + /// Sets the markers shown on the map. + /// + /// [updatedMarkers] is the full set: markers that are not in it are removed. + /// A marker that is already on the map glides to its new position. Positions + /// that arrive during a move wait in a queue. void updateMarkers(Set updatedMarkers) { final newMarkersById = keyByMarkerId(updatedMarkers); @@ -236,6 +257,9 @@ final class MapAnimationController { ); } + /// Stops all animations and releases their resources. + /// + /// The controller cannot be used afterwards. void dispose() { _animatedMarkersManager.dispose(); _animatedPolylineManager.dispose(); diff --git a/lib/src/controllers/marker_controller.dart b/lib/src/controllers/marker_controller.dart index 10c0bc9..9abb2ec 100644 --- a/lib/src/controllers/marker_controller.dart +++ b/lib/src/controllers/marker_controller.dart @@ -1,6 +1,8 @@ // Based on google_map_animation by Manish Relani (BSD-3-Clause). // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. +// Internal, not exported: public API docs are only required for exported code. +// ignore_for_file: public_member_api_docs import 'dart:collection'; diff --git a/lib/src/controllers/polyline_controller.dart b/lib/src/controllers/polyline_controller.dart index 49dfe8e..3c07012 100644 --- a/lib/src/controllers/polyline_controller.dart +++ b/lib/src/controllers/polyline_controller.dart @@ -1,6 +1,8 @@ // Based on google_map_animation by Manish Relani (BSD-3-Clause). // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. +// Internal, not exported: public API docs are only required for exported code. +// ignore_for_file: public_member_api_docs import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/managers/animated_marker_manager.dart b/lib/src/managers/animated_marker_manager.dart index 9f6ae79..5243a68 100644 --- a/lib/src/managers/animated_marker_manager.dart +++ b/lib/src/managers/animated_marker_manager.dart @@ -1,6 +1,8 @@ // Based on google_map_animation by Manish Relani (BSD-3-Clause). // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. +// Internal, not exported: public API docs are only required for exported code. +// ignore_for_file: public_member_api_docs import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/managers/animated_polyline_manager.dart b/lib/src/managers/animated_polyline_manager.dart index 3288424..077c148 100644 --- a/lib/src/managers/animated_polyline_manager.dart +++ b/lib/src/managers/animated_polyline_manager.dart @@ -1,6 +1,8 @@ // Based on google_map_animation by Manish Relani (BSD-3-Clause). // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. +// Internal, not exported: public API docs are only required for exported code. +// ignore_for_file: public_member_api_docs import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/model/animated_polyline.dart b/lib/src/model/animated_polyline.dart index b3bc4de..240a21f 100644 --- a/lib/src/model/animated_polyline.dart +++ b/lib/src/model/animated_polyline.dart @@ -5,12 +5,16 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/animator/base/polyline_animator.dart'; +/// A polyline together with the animation that draws it. class AnimatedPolyline { + /// The polyline to draw. Its points and style are the final state. final Polyline polyline; - // If null, the polyline consider as satic. + /// How the polyline is animated. If null, the polyline is static and is + /// drawn as it is. final PolylineAnimator? polylineAnimator; + /// Creates an animated polyline, or a static one when no animator is given. const AnimatedPolyline({required this.polyline, this.polylineAnimator}); @override diff --git a/lib/src/tween/bearing_tween.dart b/lib/src/tween/bearing_tween.dart index c37f4a0..e90a2c3 100644 --- a/lib/src/tween/bearing_tween.dart +++ b/lib/src/tween/bearing_tween.dart @@ -1,6 +1,8 @@ // Based on google_map_animation by Manish Relani (BSD-3-Clause). // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. +// Internal, not exported: public API docs are only required for exported code. +// ignore_for_file: public_member_api_docs import 'package:flutter/material.dart'; diff --git a/lib/src/tween/location_tween.dart b/lib/src/tween/location_tween.dart index 90d0fa2..a27eee7 100644 --- a/lib/src/tween/location_tween.dart +++ b/lib/src/tween/location_tween.dart @@ -1,6 +1,8 @@ // Based on google_map_animation by Manish Relani (BSD-3-Clause). // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. +// Internal, not exported: public API docs are only required for exported code. +// ignore_for_file: public_member_api_docs import 'package:flutter/material.dart'; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; diff --git a/lib/src/utils/math_util.dart b/lib/src/utils/math_util.dart index d1bca37..15ddf9e 100644 --- a/lib/src/utils/math_util.dart +++ b/lib/src/utils/math_util.dart @@ -1,3 +1,5 @@ +// Internal, not exported: public API docs are only required for exported code. +// ignore_for_file: public_member_api_docs //https://github.com/googlemaps/android-maps-utils // Dart imports: diff --git a/lib/src/utils/spherical_util.dart b/lib/src/utils/spherical_util.dart index f7de6c7..906195b 100644 --- a/lib/src/utils/spherical_util.dart +++ b/lib/src/utils/spherical_util.dart @@ -1,6 +1,8 @@ // Based on google_map_animation by Manish Relani (BSD-3-Clause). // https://github.com/manishrelani/google_map_animation // See LICENSE for the original notice and the changes made in this fork. +// Internal, not exported: public API docs are only required for exported code. +// ignore_for_file: public_member_api_docs import 'dart:math'; diff --git a/lib/src/utils/util.dart b/lib/src/utils/util.dart index 930acf6..8b47175 100644 --- a/lib/src/utils/util.dart +++ b/lib/src/utils/util.dart @@ -5,14 +5,21 @@ import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; import 'package:polyline_animation_plus/src/utils/spherical_util.dart'; -/// Generates points spaced dynamically based on duration - +/// Helpers to prepare data for animations. final class MapAnimationUtils { MapAnimationUtils._(); /// Tolerance used to absorb floating point error when comparing distances. static const _epsilonMeters = 1e-6; + /// Returns points along [path] that are the same distance apart, so a + /// progressive animation moves at a constant speed on the map. + /// + /// The spacing is the length of the path divided by the number of frames + /// that fit in [duration] ([frameIntervalMs] per frame). The result starts at + /// the first point of [path] and ends at its last point; the last gap can be + /// shorter than the others. A [path] with fewer than two points, or a + /// zero [duration], is returned unchanged. static List generateEquidistantPolylineByDuration({ required List path, required Duration duration, From 8275da57559c9b8fe6983ae9402f5034646be732 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:47:08 -0500 Subject: [PATCH 22/27] Rewrite the README in English and add a Spanish version README.md is the English version shown on pub.dev; README.es.md is the Spanish one, linked from the top of each file. Adds badges, a table of contents, requirements, a table of built-in animators, a custom animator example and contributing steps. --- README.es.md | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 159 +++++++++++++++++++++++-------------------- 2 files changed, 274 insertions(+), 74 deletions(-) create mode 100644 README.es.md diff --git a/README.es.md b/README.es.md new file mode 100644 index 0000000..6cea8c4 --- /dev/null +++ b/README.es.md @@ -0,0 +1,189 @@ +# polyline_animation_plus + +[![pub package](https://img.shields.io/pub/v/polyline_animation_plus.svg)](https://pub.dev/packages/polyline_animation_plus) +[![CI](https://github.com/VMichael1999/polyline_animation_plus/actions/workflows/ci.yml/badge.svg)](https://github.com/VMichael1999/polyline_animation_plus/actions/workflows/ci.yml) +[![Licencia: BSD-3-Clause](https://img.shields.io/badge/licencia-BSD--3--Clause-blue.svg)](LICENSE) + +[English](README.md) · **Español** + +Animaciones fluidas y personalizables de polylines y marcadores sobre Google Maps en Flutter. Útil para transporte, entregas, logística, seguimiento o cualquier app que necesite rutas animadas. + +> Fork de [google_map_animation](https://github.com/manishrelani/google_map_animation) de Manish Relani (BSD-3-Clause). Ver [Créditos y licencia](#créditos-y-licencia). + +

+ Polyline animada dibujándose sobre Google Maps +
+ Una polyline animada con este paquete. +

+ +## Contenido + +- [Características](#características) +- [Requisitos](#requisitos) +- [Instalación](#instalación) +- [Inicio rápido](#inicio-rápido) +- [Animators incluidos](#animators-incluidos) +- [Crea tu propio animator](#crea-tu-propio-animator) +- [Marcadores animados](#marcadores-animados) +- [Importante: no repitas IDs en `GoogleMap`](#importante-no-repitas-ids-en-googlemap) +- [Contribuir](#contribuir) +- [Créditos y licencia](#créditos-y-licencia) + +## Características + +- Polylines animadas con efectos de dibujo progresivo. +- Animaciones que se repiten o se reproducen una sola vez, con duración, curva y retrasos configurables. +- Varias polylines animadas al mismo tiempo. +- Marcadores animados que se deslizan entre posiciones y giran hacia la dirección del recorrido. +- Funciona en Android, iOS y web. +- Se basa en `google_maps_flutter_platform_interface`, por lo que no depende de una versión concreta del widget del mapa. + +## Requisitos + +- Flutter 3.22 o superior (Dart 3.4 o superior). +- Un mapa que use [`google_maps_flutter`](https://pub.dev/packages/google_maps_flutter), ya configurado con sus claves de API. + +## Instalación + +```yaml +dependencies: + polyline_animation_plus: ^1.0.4 +``` + +```dart +import 'package:polyline_animation_plus/polyline_animation_plus.dart'; +``` + +## Inicio rápido + +Crea un `MapAnimationController` cuando el mapa esté listo y pásale las polylines a dibujar. Una polyline con animator se anima; una polyline sin animator se dibuja tal cual. + +```dart +final Set polylines = { + AnimatedPolyline( + polyline: Polyline( + polylineId: const PolylineId('front'), + color: Colors.blue, + width: 4, + points: MapAnimationUtils.generateEquidistantPolylineByDuration( + path: tusCoordenadas, + duration: const Duration(seconds: 4), + ), + ), + polylineAnimator: const FadeInProgressiveAnimator( + repeat: true, + curve: Curves.linear, + duration: Duration(seconds: 4), + delayStart: Duration(seconds: 1), + ), + ), + // Sin animator: se dibuja tal cual. + AnimatedPolyline( + polyline: Polyline( + polylineId: const PolylineId('back'), + color: Colors.grey, + width: 4, + points: tusCoordenadas, + ), + ), +}; + +late MapAnimationController mapAnimationController; + +void onMapCreated(GoogleMapController controller) { + mapAnimationController = MapAnimationController( + mapId: controller.mapId, + vsync: this, // un State con TickerProviderStateMixin + polylines: polylines, + ); +} + +@override +void dispose() { + mapAnimationController.dispose(); + super.dispose(); +} +``` + +`MapAnimationUtils.generateEquidistantPolylineByDuration` agrega puntos para que queden a la misma distancia entre sí, así las animaciones progresivas avanzan a velocidad constante. Una app completa está en la carpeta [`example`](example). + +Para cambiar las polylines más tarde, llama a `mapAnimationController.updatePolylines(nuevoConjunto)`. Las polylines que no estén en el nuevo conjunto se eliminan. + +## Animators incluidos + +Todos comparten estas opciones: `duration`, `curve`, `repeat`, `repeatCount`, `reverse`, `delayStart` y `delayEnd`. Los retrasos se suman a `duration`; no la acortan. + +| Animator | Qué hace | +| --- | --- | +| `SnackAnimator` | Dibuja la línea de inicio a fin y luego la borra en el mismo sentido. | +| `FadeInProgressiveAnimator` | Hace aparecer la línea durante el primer 30 % y luego la borra desde el inicio. | +| `ColorTransitionAnimation` | Cambia el color de forma suave a través de una lista de `colors`. | + +## Crea tu propio animator + +Extiende `PolylineAnimator` y devuelve la polyline a dibujar para un `progress` dado (de 0 a 1): + +```dart +class BlinkAnimator extends PolylineAnimator { + const BlinkAnimator() + : super(duration: const Duration(seconds: 1), repeat: true); + + @override + Polyline animate(Polyline polyline, double progress) { + return polyline.copyWith( + colorParam: polyline.color.withAlpha((progress * 255).round()), + ); + } +} +``` + +`polyline` siempre es la polyline original, no el fotograma anterior. + +## Marcadores animados + +Pasa los marcadores al mismo controlador y llama a `updateMarkers` cada vez que cambie una posición, por ejemplo en cada actualización del GPS. El marcador se desliza desde su posición anterior hasta la nueva y gira hacia la dirección del recorrido. + +```dart +mapAnimationController = MapAnimationController( + mapId: controller.mapId, + vsync: this, + markers: { + Marker(markerId: const MarkerId('driver'), position: inicio), + }, + // Cuánto dura cada movimiento. Por defecto: 2 segundos. + markersAnimationDuration: const Duration(seconds: 2), + // Se llama con los marcadores actualizados en cada fotograma. + markerListener: (markers) {}, +); + +// Cuando llega una posición nueva, envía el conjunto completo de marcadores: +mapAnimationController.updateMarkers({ + Marker(markerId: const MarkerId('driver'), position: nuevaPosicion), +}); +``` + +- `updateMarkers` recibe **todos** los marcadores: los que no incluyas se eliminan del mapa. +- Las posiciones que llegan mientras un marcador sigue en movimiento esperan en una cola y se reproducen en orden. +- Un marcador que no se mueve conserva su rotación. Usa `useMarkerRotation: true` para tomar `Marker.rotation` en lugar de la dirección entre posiciones. + +## Importante: no repitas IDs en `GoogleMap` + +El controlador dibuja directamente sobre el mapa usando el `mapId`. Si el widget `GoogleMap` también recibe una polyline o un marcador con el mismo ID en sus `polylines` o `markers`, el widget sobrescribe lo que dibuja el controlador. Dale al controlador sus propios IDs y no los incluyas en los conjuntos del widget. + +## Contribuir + +Se aceptan issues y pull requests en [github.com/VMichael1999/polyline_animation_plus](https://github.com/VMichael1999/polyline_animation_plus). Antes de abrir un pull request, ejecuta: + +```bash +dart format --set-exit-if-changed lib test +flutter analyze +flutter test +``` + +Consulta el [CHANGELOG](CHANGELOG.md) para ver qué cambió en cada versión. + +## Créditos y licencia + +Este paquete es un fork de [google_map_animation](https://github.com/manishrelani/google_map_animation) de Manish Relani y se apoya en su trabajo. Lo mantiene [Michael Anthony Valdiviezo Maza](https://github.com/VMichael1999). + +BSD 3-Clause. El código original es © 2025 Manish Relani; los cambios de este fork son © 2025 Michael Anthony Valdiviezo Maza. Ambos avisos están en [LICENSE](LICENSE) y deben conservarse en las copias. diff --git a/README.md b/README.md index 99d9dd3..7894b63 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,62 @@ # polyline_animation_plus -> Fork of [google_map_animation](https://github.com/manishrelani/google_map_animation) by Manish Relani (BSD-3-Clause). See [License](#-license). +[![pub package](https://img.shields.io/pub/v/polyline_animation_plus.svg)](https://pub.dev/packages/polyline_animation_plus) +[![CI](https://github.com/VMichael1999/polyline_animation_plus/actions/workflows/ci.yml/badge.svg)](https://github.com/VMichael1999/polyline_animation_plus/actions/workflows/ci.yml) +[![License: BSD-3-Clause](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](LICENSE) -A Flutter package for creating smooth, customizable polyline animations on Google Maps. Ideal for apps in transportation, delivery, logistics, tracking, or any project that needs animated route visualizations. +**English** · [Español](README.es.md) -## 🎥 Demo +Smooth, customizable polyline and marker animations for Google Maps in Flutter. Useful for transportation, delivery, logistics, tracking or any app that needs animated routes. + +> Fork of [google_map_animation](https://github.com/manishrelani/google_map_animation) by Manish Relani (BSD-3-Clause). See [Credits and license](#credits-and-license).

-Animated polyline drawing on Google Maps -
-This animation represents how the plugin behaves + Animated polyline drawing on Google Maps +
+ An animated polyline drawn with this package.

---- - -## ✨ Features +## Contents -- 🎬 **Animated polylines** with progressive drawing effects -- 🔁 **Repeatable** or one‑shot animations -- ⏱️ **Custom duration**, delay, and animation curves -- 📍 **Animated markers** that glide between positions and turn towards the direction of travel -- 🗺️ Works on **Android, iOS and web** (Google Maps) -- 🧩 Supports **multiple animated polylines** simultaneously -- ⚡ Built using the `google_maps_flutter_platform_interface` +- [Features](#features) +- [Requirements](#requirements) +- [Installation](#installation) +- [Quick start](#quick-start) +- [Built-in animators](#built-in-animators) +- [Create your own animator](#create-your-own-animator) +- [Animated markers](#animated-markers) +- [Important: do not reuse IDs in `GoogleMap`](#important-do-not-reuse-ids-in-googlemap) +- [Contributing](#contributing) +- [Credits and license](#credits-and-license) ---- +## Features -## 🚀 Getting Started +- Animated polylines with progressive drawing effects. +- Repeating or one-shot animations, with custom duration, curve and delays. +- Several animated polylines at the same time. +- Animated markers that glide between positions and turn towards the direction of travel. +- Works on Android, iOS and web. +- Built on `google_maps_flutter_platform_interface`: it does not depend on a specific map widget version. -Add the package to your `pubspec.yaml`: +## Requirements -```yaml -dependencies: - polyline_animation_plus: ^1.0.4 -``` +- Flutter 3.22 or newer (Dart 3.4 or newer). +- A map using [`google_maps_flutter`](https://pub.dev/packages/google_maps_flutter), already set up with its API keys. -Or if using locally (for development): +## Installation ```yaml dependencies: - polyline_animation_plus: - path: ../polyline_animation_plus + polyline_animation_plus: ^1.0.4 ``` -Import it: - ```dart import 'package:polyline_animation_plus/polyline_animation_plus.dart'; ``` ---- +## Quick start -## 📌 Usage Example - -Below is a basic example of how to animate a polyline on Google Maps. +Create a `MapAnimationController` when the map is ready and give it the polylines to draw. A polyline with an animator is animated; a polyline without one is drawn as it is. ```dart final Set polylines = { @@ -74,6 +77,7 @@ final Set polylines = { delayStart: Duration(seconds: 1), ), ), + // No animator: drawn as it is. AnimatedPolyline( polyline: Polyline( polylineId: const PolylineId('back'), @@ -86,18 +90,14 @@ final Set polylines = { late MapAnimationController mapAnimationController; -onMapCreated(GoogleMapController controller) { +void onMapCreated(GoogleMapController controller) { mapAnimationController = MapAnimationController( mapId: controller.mapId, - vsync: this, + vsync: this, // a State with TickerProviderStateMixin polylines: polylines, ); } -``` -Remember to release the controller when the map goes away: - -```dart @override void dispose() { mapAnimationController.dispose(); @@ -105,13 +105,43 @@ void dispose() { } ``` -More complete examples can be found in the `/example` folder. +`MapAnimationUtils.generateEquidistantPolylineByDuration` adds points so they are evenly spaced, which makes progressive animations move at a constant speed. A complete app is in the [`example`](example) folder. ---- +To change the polylines later, call `mapAnimationController.updatePolylines(newSet)`. Polylines missing from the new set are removed. -## 📍 Animated markers +## Built-in animators -Pass the markers to the same controller and call `updateMarkers` every time a position changes (for example, on each GPS update). The marker glides from its previous position to the new one and rotates towards the direction of travel. +All animators share these options: `duration`, `curve`, `repeat`, `repeatCount`, `reverse`, `delayStart` and `delayEnd`. The delays are added to `duration`; they do not shorten it. + +| Animator | What it does | +| --- | --- | +| `SnackAnimator` | Draws the line from start to end, then erases it in the same direction. | +| `FadeInProgressiveAnimator` | Fades the line in during the first 30% and then erases it from the start. | +| `ColorTransitionAnimation` | Changes the color smoothly through a list of `colors`. | + +## Create your own animator + +Extend `PolylineAnimator` and return the polyline to draw for a given `progress` (from 0 to 1): + +```dart +class BlinkAnimator extends PolylineAnimator { + const BlinkAnimator() + : super(duration: const Duration(seconds: 1), repeat: true); + + @override + Polyline animate(Polyline polyline, double progress) { + return polyline.copyWith( + colorParam: polyline.color.withAlpha((progress * 255).round()), + ); + } +} +``` + +`polyline` is always the original polyline, not the previous frame. + +## Animated markers + +Pass the markers to the same controller and call `updateMarkers` each time a position changes, for example on every GPS update. The marker glides from its previous position to the new one and rotates towards the direction of travel. ```dart mapAnimationController = MapAnimationController( @@ -136,43 +166,24 @@ mapAnimationController.updateMarkers({ - Positions that arrive while a marker is still moving wait in a queue and are played in order. - A marker that does not move keeps its rotation. Set `useMarkerRotation: true` to use `Marker.rotation` instead of the heading between positions. ---- - -## ⚠️ Do not pass the same IDs to `GoogleMap` - -The controller draws directly on the map, using the `mapId`. If the `GoogleMap` widget also receives a polyline or marker with the same ID in its `polylines` or `markers`, the widget will overwrite what the controller draws. Give the controller its own IDs and leave them out of the widget's sets. +## Important: do not reuse IDs in `GoogleMap` ---- +The controller draws directly on the map, using the `mapId`. If the `GoogleMap` widget also receives a polyline or marker with the same ID in its `polylines` or `markers`, the widget overwrites what the controller draws. Give the controller its own IDs and leave them out of the widget's sets. -## 📚 Additional Information +## Contributing -- Issues and feature requests: **GitHub Issues** -- Repository: https://github.com/VMichael1999/polyline_animation_plus -- Contributions are welcome! Submit PRs to improve animations or extend support. -- Based on [google_map_animation](https://github.com/manishrelani/google_map_animation) by Manish Relani. +Issues and pull requests are welcome at [github.com/VMichael1999/polyline_animation_plus](https://github.com/VMichael1999/polyline_animation_plus). Before opening a pull request, run: -## 👤 Author / Developer - -**Michael Anthony Valdiviezo Maza** - -Flutter & Mobile Developer focused on mobility, ride‑hailing, logistics and real‑time map experiences. Maintainer of this fork, which builds on the original work of Manish Relani. - -**Areas of focus** -- Google Maps & geolocation (polylines, tracking, animations) -- Ride‑hailing / fleet dispatch flows -- Real‑time mobility UX and performance optimization -- White‑label transportation platforms (B2B & B2C) - -**Connect** -- GitHub: https://github.com/VMichael1999 - -If you use this package in your project, feel free to open an issue or PR — contributions and ideas are welcome. - ---- +```bash +dart format --set-exit-if-changed lib test +flutter analyze +flutter test +``` +See the [CHANGELOG](CHANGELOG.md) for what changed in each version. -## 📄 License +## Credits and license -BSD 3-Clause. The original code is © 2025 Manish Relani ([google_map_animation](https://github.com/manishrelani/google_map_animation)); changes in this fork are © 2025 Michael Anthony Valdiviezo Maza. Both notices are in [LICENSE](LICENSE) and must be kept in copies. +This package is a fork of [google_map_animation](https://github.com/manishrelani/google_map_animation) by Manish Relani and builds on his work. It is maintained by [Michael Anthony Valdiviezo Maza](https://github.com/VMichael1999). -Fork additions: see [CHANGELOG](CHANGELOG.md). +BSD 3-Clause. The original code is © 2025 Manish Relani; the changes in this fork are © 2025 Michael Anthony Valdiviezo Maza. Both notices are in [LICENSE](LICENSE) and must be kept in copies. From e34fbbf17039d1ed688a3a4a38bbd68237343d63 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:53:40 -0500 Subject: [PATCH 23/27] Apply the analyzer excludes added by recent Flutter versions Recent Flutter rewrites analysis_options.yaml on pub get, which made flutter pub publish --dry-run warn about modified files in CI. --- analysis_options.yaml | 3 +++ example/analysis_options.yaml | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index cf1dc8a..ab14d53 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,3 +1,6 @@ +analyzer: + exclude: + - build/** include: package:flutter_lints/flutter.yaml # Additional information about this file can be found at diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index 0d29021..bf8d421 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -7,6 +7,15 @@ # The following line activates a set of recommended lints for Flutter apps, # packages, and plugins designed to encourage good coding practices. +analyzer: + exclude: + - build/** + - android/** + - ios/** + - web/** + - windows/** + - macos/** + - linux/** include: package:flutter_lints/flutter.yaml linter: From 52a587293fbd8a992fa83fe561378edec652a274 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:57:40 -0500 Subject: [PATCH 24/27] Support Flutter 3.22: limited repeats and DelayedCurvedAnimation Both failed to compile on Flutter 3.22.0, the minimum declared in the pubspec: - AnimationController.repeat(count:) does not exist there. Limited repeats now use a small Simulation with the same timing as repeat(count:). - DelayedCurvedAnimation overrode isAnimating, which CurvedAnimation does not have in 3.22. The getter is renamed to isInAnimationPhase (internal class). Adds tests for repeatCount, with and without reverse. --- .../animations/delayed_curved_animation.dart | 4 +- lib/src/controllers/polyline_controller.dart | 48 ++++++++++++-- .../delayed_curved_animation_test.dart | 6 +- .../controllers/polyline_controller_test.dart | 64 +++++++++++++++++++ 4 files changed, 113 insertions(+), 9 deletions(-) diff --git a/lib/src/animations/delayed_curved_animation.dart b/lib/src/animations/delayed_curved_animation.dart index 2f3aefd..d780840 100644 --- a/lib/src/animations/delayed_curved_animation.dart +++ b/lib/src/animations/delayed_curved_animation.dart @@ -78,6 +78,6 @@ class DelayedCurvedAnimation extends CurvedAnimation { parent.value > (1 - delayEnd.inMicroseconds / totalDuration.inMicroseconds); - @override - bool get isAnimating => !isInStartDelay && !isInEndDelay; + /// Whether the animation is between its start and end delays. + bool get isInAnimationPhase => !isInStartDelay && !isInEndDelay; } diff --git a/lib/src/controllers/polyline_controller.dart b/lib/src/controllers/polyline_controller.dart index 3c07012..2cafd55 100644 --- a/lib/src/controllers/polyline_controller.dart +++ b/lib/src/controllers/polyline_controller.dart @@ -62,11 +62,19 @@ class PolylineAnimationController { ); } - if (polylineAnimator.repeat) { - _controller.repeat( - reverse: polylineAnimator.reverse, - count: polylineAnimator.repeatCount, + final repeatCount = polylineAnimator.repeatCount; + if (polylineAnimator.repeat && repeatCount != null) { + // AnimationController.repeat(count:) does not exist in older Flutter + // versions, so limited repeats use their own simulation. + _controller.animateWith( + _LimitedRepeatSimulation( + passes: repeatCount, + reverse: polylineAnimator.reverse, + period: totalDuration, + ), ); + } else if (polylineAnimator.repeat) { + _controller.repeat(reverse: polylineAnimator.reverse); } else { _controller.forward(); } @@ -95,3 +103,35 @@ class PolylineAnimationController { _controller.dispose(); } } + +/// Plays [passes] passes from 0 to 1, or alternately 0 to 1 and 1 to 0 when +/// [reverse] is true, each lasting [period]. It behaves like +/// `AnimationController.repeat(count: passes)`. +class _LimitedRepeatSimulation extends Simulation { + _LimitedRepeatSimulation({ + required this.passes, + required this.reverse, + required Duration period, + }) : _periodSeconds = period.inMicroseconds / Duration.microsecondsPerSecond; + + final int passes; + final bool reverse; + final double _periodSeconds; + + bool _isForward(int pass) => !reverse || pass.isEven; + + @override + double x(double timeInSeconds) { + if (isDone(timeInSeconds)) return _isForward(passes - 1) ? 1.0 : 0.0; + + final pass = timeInSeconds ~/ _periodSeconds; + final fraction = (timeInSeconds - pass * _periodSeconds) / _periodSeconds; + return _isForward(pass) ? fraction : 1.0 - fraction; + } + + @override + double dx(double timeInSeconds) => 0.0; + + @override + bool isDone(double timeInSeconds) => timeInSeconds >= passes * _periodSeconds; +} diff --git a/test/animations/delayed_curved_animation_test.dart b/test/animations/delayed_curved_animation_test.dart index 536522e..5e16c82 100644 --- a/test/animations/delayed_curved_animation_test.dart +++ b/test/animations/delayed_curved_animation_test.dart @@ -39,12 +39,12 @@ void main() { controller.value = 0.1; expect(animation.value, 0); expect(animation.isInStartDelay, isTrue); - expect(animation.isAnimating, isFalse); + expect(animation.isInAnimationPhase, isFalse); controller.value = 0.9; expect(animation.value, 1); expect(animation.isInEndDelay, isTrue); - expect(animation.isAnimating, isFalse); + expect(animation.isInAnimationPhase, isFalse); }); test('maps the middle of the cycle to the middle of the animation', () { @@ -53,7 +53,7 @@ void main() { expect(animation.value, closeTo(0.5, 1e-9)); expect(animation.animationProgress, closeTo(0.5, 1e-9)); - expect(animation.isAnimating, isTrue); + expect(animation.isInAnimationPhase, isTrue); }); test('animationProgress is 0 and 1 at the ends', () { diff --git a/test/controllers/polyline_controller_test.dart b/test/controllers/polyline_controller_test.dart index 0f7dadc..6b375ce 100644 --- a/test/controllers/polyline_controller_test.dart +++ b/test/controllers/polyline_controller_test.dart @@ -8,6 +8,8 @@ class _RecordingAnimator extends PolylineAnimator { required super.duration, super.delayStart, super.repeat, + super.repeatCount, + super.reverse, }); static final progress = []; @@ -100,4 +102,66 @@ void main() { controller.dispose(); }); }); + + group('repeatCount', () { + PolylineAnimationController create( + WidgetTester tester, { + required int count, + bool reverse = false, + }) => + PolylineAnimationController( + vsync: tester, + polyline: polyline, + polylineListener: (_) {}, + polylineAnimator: _RecordingAnimator( + duration: const Duration(seconds: 1), + repeat: true, + repeatCount: count, + reverse: reverse, + ), + ); + + testWidgets('plays the given number of cycles and then stops once', ( + tester, + ) async { + final controller = create(tester, count: 3); + await tester.pump(); + + await tester.pump(const Duration(milliseconds: 2500)); + expect(_RecordingAnimator.stops, 0); + + await tester.pump(const Duration(milliseconds: 700)); + expect(_RecordingAnimator.stops, 1); + + final frames = _RecordingAnimator.progress.length; + await tester.pump(const Duration(seconds: 2)); + expect(_RecordingAnimator.progress.length, frames); + expect(_RecordingAnimator.stops, 1); + controller.dispose(); + }); + + testWidgets('restarts from the beginning on every cycle', (tester) async { + final controller = create(tester, count: 2); + await tester.pump(); + await tester.pump(const Duration(milliseconds: 1500)); + + expect(_RecordingAnimator.progress.last, closeTo(0.5, 0.05)); + controller.dispose(); + }); + + testWidgets('with reverse every forward or backward pass counts', ( + tester, + ) async { + final controller = create(tester, count: 2, reverse: true); + await tester.pump(); + + await tester.pump(const Duration(milliseconds: 1500)); + expect(_RecordingAnimator.progress.last, closeTo(0.5, 0.05)); + expect(_RecordingAnimator.stops, 0); + + await tester.pump(const Duration(milliseconds: 700)); + expect(_RecordingAnimator.stops, 1); + controller.dispose(); + }); + }); } From 55276e5dd6ef7c15aa66bfadcfac9ae38b8a1bd0 Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 15:59:35 -0500 Subject: [PATCH 25/27] Update the example's Android toolchain for current Flutter Flutter stable now requires Gradle 8.14 or newer, so the Android build of the example failed. Moves to Gradle 9.3.1, AGP 9.1.0, Kotlin 2.4.0 and Java 17, as in the current Flutter template, and uses flutter.ndkVersion. --- example/android/app/build.gradle.kts | 17 +++++++++-------- example/android/gradle.properties | 4 ++++ .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/android/settings.gradle.kts | 4 ++-- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/example/android/app/build.gradle.kts b/example/android/app/build.gradle.kts index d77dd1a..4da37e6 100644 --- a/example/android/app/build.gradle.kts +++ b/example/android/app/build.gradle.kts @@ -1,6 +1,5 @@ plugins { id("com.android.application") - id("kotlin-android") // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. id("dev.flutter.flutter-gradle-plugin") } @@ -8,15 +7,11 @@ plugins { android { namespace = "com.example.example" compileSdk = flutter.compileSdkVersion - ndkVersion = "27.0.12077973" + ndkVersion = flutter.ndkVersion compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - - kotlinOptions { - jvmTarget = JavaVersion.VERSION_11.toString() + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } defaultConfig { @@ -39,6 +34,12 @@ android { } } +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} + flutter { source = "../.." } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index f018a61..475a628 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,3 +1,7 @@ org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError android.useAndroidX=true android.enableJetifier=true +# This builtInKotlin flag was added automatically by Flutter migrator +android.builtInKotlin=false +# This newDsl flag was added automatically by Flutter migrator +android.newDsl=false diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index afa1e8e..a20f2c4 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip diff --git a/example/android/settings.gradle.kts b/example/android/settings.gradle.kts index a439442..9d5a6fe 100644 --- a/example/android/settings.gradle.kts +++ b/example/android/settings.gradle.kts @@ -18,8 +18,8 @@ pluginManagement { plugins { id("dev.flutter.flutter-plugin-loader") version "1.0.0" - id("com.android.application") version "8.7.0" apply false - id("org.jetbrains.kotlin.android") version "1.8.22" apply false + id("com.android.application") version "9.1.0" apply false + id("org.jetbrains.kotlin.android") version "2.4.0" apply false } include(":app") From ce7ee2e321b0ffcffd63ee64c6c4bf650926c14a Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 16:00:17 -0500 Subject: [PATCH 26/27] Skip the example when resolving dependencies on the minimum Flutter The example needs Dart 3.7, so flutter pub get/upgrade/downgrade failed on Flutter 3.22.0 while resolving it. The compatibility job now passes --no-example and --no-pub, since it only checks lib and test. --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 512d621..5660185 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,17 +60,17 @@ jobs: flutter-version: ${{ matrix.flutter != 'stable' && matrix.flutter || '' }} channel: stable cache: true + # The example needs a newer SDK than the package, so it is left out of + # dependency resolution (--no-example) and only lib and test are checked. - name: Resolve dependencies run: | if [ "${{ matrix.deps }}" = "minimum" ]; then - flutter pub downgrade + flutter pub downgrade --no-example else - flutter pub upgrade + flutter pub upgrade --no-example fi - # The example needs a newer SDK than the package, so only lib and test - # are analyzed here. - - run: flutter analyze lib test - - run: flutter test + - run: flutter analyze --no-pub lib test + - run: flutter test --no-pub publish-dry-run: name: Publish dry run From cffbec89f503caa769b1970d5502f56fed93748f Mon Sep 17 00:00:00 2001 From: VMichael1999 Date: Sun, 25 Oct 2026 16:08:19 -0500 Subject: [PATCH 27/27] Use dart pub in the compatibility job flutter pub upgrade --no-example resolves the packages but then fails with "example/.dart_tool/package_config.json does not exist" on a clean checkout. dart pub does the same resolution without touching the example. --- .github/workflows/ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5660185..5593648 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,12 +62,14 @@ jobs: cache: true # The example needs a newer SDK than the package, so it is left out of # dependency resolution (--no-example) and only lib and test are checked. + # `dart pub` is used because `flutter pub upgrade` still tries to prepare + # the example afterwards and fails when example/.dart_tool is missing. - name: Resolve dependencies run: | if [ "${{ matrix.deps }}" = "minimum" ]; then - flutter pub downgrade --no-example + dart pub downgrade --no-example else - flutter pub upgrade --no-example + dart pub upgrade --no-example fi - run: flutter analyze --no-pub lib test - run: flutter test --no-pub