import 'package:flutter/material.dart'; class PolygonAnimController extends AnimationController { late List> _tweens; late List> _animations; late List _currentCoords; void Function(List coords)? onCoordsChange; PolygonAnimController( {required int len, required super.vsync, required super.duration}) { // _animController = AnimationController( // vsync: this, duration: const Duration(milliseconds: 400)); _tweens = List.generate(len, (index) => Tween()); _animations = List.generate(len, (index) => _tweens[index].animate(this)); _currentCoords = List.generate(len, (index) => const Offset(0, 0)); addListener(_listener); } @override void dispose() { removeListener(_listener); super.dispose(); } void _listener() { List values = List.generate(_animations.length, (index) => _animations[index].value); onCoordsChange?.call(values); } void startAnim(List freshCoords) { assert(freshCoords.length == _tweens.length, "Their length must be equal!"); for (int i = 0, len = _tweens.length; i < len; i++) { _tweens[i].begin = _currentCoords[i]; _tweens[i].end = freshCoords[i]; } _currentCoords = freshCoords; reset(); forward(); } }