diff --git a/coverage/lcov.info b/coverage/lcov.info index 193a091..7a85e1f 100644 --- a/coverage/lcov.info +++ b/coverage/lcov.info @@ -1,218 +1,214 @@ -SF:lib\src\animator_key.dart -DA:19,2 -DA:20,2 -DA:71,4 -DA:72,4 -DA:81,4 -DA:82,2 -DA:83,2 -DA:89,2 -DA:91,2 -DA:93,2 -DA:95,2 -DA:111,1 -DA:121,2 -DA:130,1 -DA:134,1 -DA:135,2 -DA:136,1 -DA:137,2 -DA:138,1 -DA:139,3 -DA:142,1 -DA:144,2 -DA:147,1 -DA:148,2 -DA:150,2 -DA:152,4 -DA:155,1 -DA:157,2 -DA:160,1 -DA:162,2 -LF:30 -LH:30 -end_of_record -SF:lib\src\animator.dart -DA:9,2 -DA:11,2 -DA:14,2 -DA:25,2 +SF:lib/src/animator_rebuilder.dart +DA:22,1 +DA:27,1 +DA:29,1 +DA:30,1 +DA:34,1 +DA:35,3 +DA:37,1 +DA:39,1 +DA:40,6 DA:43,1 -DA:44,2 -DA:74,2 -DA:75,2 -DA:161,2 -DA:162,2 -DA:166,2 -DA:177,2 -DA:178,2 -DA:179,2 -DA:180,2 -DA:181,2 -DA:182,2 -DA:183,2 -DA:184,2 -DA:185,2 -DA:186,2 -DA:187,2 -DA:188,2 -DA:189,2 -DA:193,2 -DA:201,2 -DA:203,2 -DA:204,6 -DA:207,2 -DA:216,2 -DA:217,2 -DA:218,6 -DA:226,2 -DA:229,2 -DA:231,2 -DA:232,8 -DA:233,0 -DA:237,2 -DA:239,2 -DA:240,6 -DA:241,6 -DA:242,4 -DA:245,4 -DA:246,4 -DA:247,2 -DA:248,4 -DA:249,4 -DA:250,4 -DA:251,4 -DA:252,3 -DA:260,1 -DA:272,2 -DA:273,4 -DA:275,2 -DA:276,4 -DA:277,2 -DA:280,2 -DA:281,12 -LF:58 -LH:57 -end_of_record -SF:lib\src\animator_state.dart -DA:15,1 -DA:16,1 DA:45,2 -DA:51,2 -DA:52,2 -DA:55,1 +DA:46,1 +DA:49,1 +DA:51,3 +DA:53,1 +DA:54,2 +LF:16 +LH:16 +end_of_record +SF:lib/src/animator_key.dart +DA:15,2 +DA:17,2 +DA:50,2 +DA:53,1 +DA:54,2 DA:56,1 DA:57,2 -DA:58,4 +DA:59,1 +DA:61,2 +DA:64,1 +DA:66,1 +DA:67,2 +DA:69,2 +DA:72,1 +DA:80,1 +DA:81,1 +DA:89,1 +DA:92,2 +DA:94,4 +DA:97,1 +DA:99,1 +DA:100,1 +DA:102,2 +DA:105,2 +DA:106,6 +DA:111,1 +DA:112,2 +DA:113,3 +LF:28 +LH:28 +end_of_record +SF:lib/src/animator_state.dart +DA:49,2 +DA:55,10 +DA:56,2 +DA:57,6 +DA:59,6 DA:60,2 -DA:61,6 -DA:64,6 -DA:65,6 +DA:62,2 +DA:63,2 +DA:66,10 DA:69,1 -DA:71,2 +DA:70,2 DA:72,2 -DA:75,1 -DA:77,2 -DA:78,3 -DA:82,6 -DA:83,2 -DA:84,4 -DA:94,2 -DA:95,10 -DA:96,4 -DA:98,4 -DA:99,2 -DA:102,6 +DA:74,6 +DA:75,4 +DA:79,10 +DA:80,4 +DA:84,2 +DA:85,4 +DA:87,2 +DA:89,2 +DA:90,2 +DA:93,2 DA:103,2 DA:104,2 -DA:105,2 -DA:108,4 -DA:109,4 -DA:110,2 -DA:112,1 +DA:107,2 +DA:108,1 +DA:111,1 DA:113,4 -DA:119,10 -DA:120,2 +DA:125,2 +DA:127,4 +DA:130,2 +DA:131,2 +DA:132,4 +LF:33 +LH:33 +end_of_record +SF:lib/src/animator.dart +DA:18,2 +DA:36,2 +DA:115,2 +DA:116,2 +DA:120,4 +DA:121,4 DA:122,4 -DA:123,4 -DA:124,8 +DA:123,8 +DA:125,8 +DA:127,8 DA:128,4 -DA:129,2 -DA:133,2 -DA:134,6 -DA:135,4 -DA:136,6 -DA:140,2 -DA:141,2 -DA:142,4 +DA:129,5 +DA:131,2 +DA:132,4 +DA:133,4 +DA:134,8 +DA:136,4 +DA:137,3 +DA:139,4 +DA:140,6 DA:146,2 -DA:147,2 DA:148,2 +DA:149,4 +DA:150,2 DA:151,2 -DA:152,4 DA:153,4 -DA:156,2 -DA:157,4 +DA:154,4 +DA:157,2 DA:158,4 +DA:160,2 DA:161,2 -DA:164,1 +DA:162,8 DA:165,2 -DA:166,1 +DA:167,2 DA:168,6 DA:169,4 -DA:170,3 -DA:171,1 -DA:172,1 -DA:173,1 -DA:174,1 -DA:176,2 -DA:182,2 -DA:183,2 -DA:184,4 -DA:186,4 -DA:189,2 -DA:190,6 +DA:170,2 +DA:171,2 +DA:172,12 +DA:174,8 +DA:175,8 +DA:176,8 +DA:177,8 +DA:179,8 +DA:181,2 +DA:185,2 +DA:187,4 +DA:188,2 +DA:191,2 DA:193,2 DA:194,2 -DA:195,4 +DA:195,2 +DA:196,12 +DA:198,2 DA:199,2 -DA:200,2 -DA:201,2 -DA:202,2 -DA:203,2 -DA:204,2 -DA:205,4 -DA:206,4 -DA:207,3 -DA:209,10 -DA:210,4 -DA:211,6 -DA:212,2 -DA:215,2 -DA:216,8 -DA:217,2 -DA:218,4 -DA:220,2 -DA:221,2 -DA:222,2 -DA:224,2 -DA:225,8 -DA:226,4 -LF:103 -LH:103 +DA:200,4 +LF:56 +LH:56 end_of_record -SF:lib\src\animator_rebuilder.dart -DA:16,1 -DA:21,1 -DA:22,1 -DA:23,1 -DA:25,1 -DA:27,2 -DA:28,1 -DA:29,1 -DA:30,1 -DA:31,1 -DA:32,3 -LF:11 -LH:11 +SF:lib/src/animate_widget.dart +DA:80,1 +DA:97,1 +DA:99,1 +DA:100,1 +DA:104,2 +DA:105,2 +DA:106,2 +DA:107,2 +DA:108,2 +DA:109,2 +DA:110,2 +DA:111,2 +DA:112,2 +DA:113,4 +DA:114,2 +DA:116,2 +DA:119,2 +DA:122,1 +DA:124,1 +DA:125,2 +DA:126,2 +DA:127,1 +DA:128,2 +DA:129,2 +DA:135,1 +DA:137,1 +DA:138,4 +DA:139,4 +DA:140,2 +DA:141,4 +DA:142,2 +DA:144,1 +DA:145,1 +DA:148,2 +DA:149,4 +DA:151,4 +DA:152,4 +DA:153,2 +DA:155,4 +DA:156,2 +DA:159,3 +DA:163,1 +DA:165,1 +DA:166,1 +DA:167,3 +DA:168,4 +DA:170,2 +DA:179,1 +DA:180,1 +DA:181,2 +DA:184,3 +DA:186,1 +DA:187,2 +DA:191,1 +DA:192,2 +DA:196,1 +DA:199,1 +DA:200,2 +DA:206,1 +DA:207,1 +DA:208,2 +LF:61 +LH:61 end_of_record diff --git a/lib/animator.dart b/lib/animator.dart index 59f530b..7d499d9 100644 --- a/lib/animator.dart +++ b/lib/animator.dart @@ -3,3 +3,5 @@ library animator; export 'package:animator/src/animate_widget.dart'; export 'package:animator/src/animator.dart'; export 'package:states_rebuilder/src/extensions/type_extension.dart'; +export 'package:states_rebuilder/src/builders/child.dart' + show Child, Child2, Child3; diff --git a/lib/src/animator.dart b/lib/src/animator.dart index 932f315..586515b 100644 --- a/lib/src/animator.dart +++ b/lib/src/animator.dart @@ -5,7 +5,7 @@ import 'package:states_rebuilder/states_rebuilder.dart'; part 'animator_key.dart'; part 'animator_rebuilder.dart'; part 'animator_state.dart'; -part 'child.dart'; +// part 'child.dart'; ///{@template animator} ///A facade widget that hide the complexity of setting animation in Flutter @@ -141,7 +141,7 @@ class _AnimatorState extends State> { } }, ); - late AnimatorState animatorState; + late AnimatorStateImp animatorState; @override void initState() { @@ -165,10 +165,9 @@ class _AnimatorState extends State> { @override void didUpdateWidget(covariant Animator oldWidget) { super.didUpdateWidget(oldWidget); - final animatorImp = animatorState as AnimatorStateImp; - animatorImp.animator = widget; + animatorState.animator = widget; if (widget.resetAnimationOnRebuild) { - animatorImp + animatorState ..resetAnimation( tween: oldWidget.tween != widget.tween ? widget.tween : null, tweenMap: @@ -183,6 +182,12 @@ class _AnimatorState extends State> { } } + @override + void dispose() { + animatorState.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return On.animation( diff --git a/lib/src/animator_state.dart b/lib/src/animator_state.dart index 5299289..931dc5b 100644 --- a/lib/src/animator_state.dart +++ b/lib/src/animator_state.dart @@ -132,280 +132,3 @@ class AnimatorStateImp implements AnimatorState { _animationMap.clear(); } } - -// ///{@template animatorState} -// ///The state of [Animator] widget. -// /// -// ///From the parameter defined in the [Animator] widget, it instantiates -// ///the animation. -// /// -// ///{@endtemplate} -// abstract class AnimatorState { -// ///{@macro animatorState} -// factory AnimatorState(Animator animator, void Function() rebuildStates) { -// return AnimatorStateImp(animator, rebuildStates); -// } - -// void resetAnimation({ -// Tween? tween, -// Map? tweenMap, -// Duration? duration, -// Curve? curve, -// int? repeats, -// int? cycles, -// }); - -// void triggerAnimation({bool restart = false}); - -// ///The [AnimationController] for an animation. -// /// -// ///It lets you perform tasks such as: -// ///* paly, reverse, stop animation -// ///* Set the animation to a specific. -// AnimationController get controller; - -// ///The [Animation] object -// Animation get animation; - -// ///get the animation of provided name -// /// -// ///It will throw if [Animator.tweenMap] is null -// Animation getAnimation(String name); - -// ///The value of the [animation] -// T get value; - -// ///The value map of the [Animator.tweenMap]; -// R getValue(String name); -// } - -// ///Implementation of [AnimatorState] -// class AnimatorStateImp implements AnimatorState { -// void Function() rebuildStates; - -// ///Implementation of [AnimatorState] -// AnimatorStateImp(Animator? animator, this.rebuildStates) { -// if (animator != null) { -// this.animator = animator; -// } -// } - -// ///The animator widget the AnimatorState is associated with -// late Animator animator; -// // -// AnimationController? _controller; -// @override -// AnimationController get controller => _controller!; -// // -// Animation? _animation; -// @override -// Animation get animation => -// _animation ??= controller.drive(_curveTween as Animatable); - -// // _animation!; -// @override -// T get value { -// return _curveTween.evaluate(controller)!; -// } - -// late Animatable _curveTween; - -// late Duration _duration = animator.duration!; -// set duration(Duration duration) { -// if (_duration != duration) { -// _duration = duration; -// _controller!.duration = _duration; -// } -// } - -// late Curve _curve = animator.curve!; -// set curve(Curve curve) { -// _curve = curve; -// } - -// // -// late Tween? _tween = animator.tween; -// set tween(Tween? tween) { -// tween ??= (Tween(begin: 0, end: 1) as Tween); -// _curveTween = tween.chain(CurveTween(curve: _curve)); -// _tween = tween; -// } - -// Map> _tweenMap = {}; -// set tweenMap(Map newTweens) { -// _tweenMap = newTweens; -// _animationMap.clear(); -// _valuesMap.clear(); -// _tweenMap.forEach((key, tween) { -// _curvedTweenMap[key] = tween.chain(CurveTween(curve: _curve)); -// }); -// } - -// Map> _curvedTweenMap = {}; - -// final Map _animationMap = {}; - -// @override -// Animation getAnimation(String name) { -// assert(_tweenMap.isNotEmpty); -// var anim = _animationMap[name]; -// if (anim != null) { -// return anim as Animation; -// } -// anim = controller.drive(_curvedTweenMap[name]!); -// _animationMap[name] = anim; -// return anim as Animation; -// } - -// Map _valuesMap = {}; -// @override -// R getValue(String name) { -// assert(_tweenMap.isNotEmpty); -// assert(_curvedTweenMap[name] != null); -// final val = _curvedTweenMap[name]!.evaluate(controller); -// _valuesMap[name] = val; -// return val; -// } - -// // -// bool get _triggerOnInit => animator.triggerOnInit != null -// ? animator.triggerOnInit! -// : animator.animatorKey != null -// ? false -// : true; -// // -// late int _repeatCount; -// late bool _isCycle; -// //used to skip the dismiss status when cycle is defined -// bool _skipDismissStatus = false; -// // - -// ///initialize animation -// void initAnimation(TickerProvider ticker) { -// _controller ??= AnimationController( -// duration: _duration, -// vsync: ticker, -// ); - -// resetAnimation( -// tween: animator.tween, -// tweenMap: animator.tweenMap, -// repeats: animator.repeats, -// cycles: animator.cycles, -// ); - -// _addAnimationListeners(); - -// if (animator.statusListener != null) { -// controller.addStatusListener( -// (status) => animator.statusListener!(status, this), -// ); -// } - -// if (animator.animatorKey != null) { -// controller.addListener((animator.animatorKey as AnimatorKeyImp)._rebuild); -// } - -// if (_triggerOnInit == true) { -// triggerAnimation(); -// } -// } - -// void resetAnimation({ -// Tween? tween, -// Map? tweenMap, -// Duration? duration, -// Curve? curve, -// int? repeats, -// int? cycles, -// }) { -// this.duration = duration ?? _duration; -// this.curve = curve ?? _curve; -// this.tween = tween ?? _tween; -// this.tweenMap = tweenMap ?? _tweenMap; - -// _animation = null; - -// _isCycle = repeats == null && cycles != null; -// _repeatCount = _setRepeatCount(animator.repeats, animator.cycles); -// _addAnimationStatusListener(_getStatusListenerCallBack); -// } - -// void _addAnimationListeners() { -// controller.addListener(rebuildStates); -// if (animator.customListener != null) { -// controller.addListener(() => animator.customListener!(this)); -// } -// } - -// /// -// void _addAnimationStatusListener(void Function(AnimationStatus status) fn) { -// _removeStatusListener(fn); -// _addStatusListener(fn); -// } - -// void _addStatusListener(void Function(AnimationStatus) listener) { -// controller.addStatusListener(listener); -// } - -// void _removeStatusListener(void Function(AnimationStatus)? listener) { -// if (listener == null) return; -// controller.removeStatusListener(listener); -// } - -// ///Start the animation -// void triggerAnimation({bool restart = false}) { -// if (restart) { -// _skipDismissStatus = true; -// controller.value = 0; -// _skipDismissStatus = false; -// } -// if (controller.status == AnimationStatus.dismissed) { -// controller.forward(); -// } else if (controller.status == AnimationStatus.completed) { -// if (!_isCycle) { -// controller -// ..value = 0 -// ..forward(); -// } else { -// controller.reverse(); -// } -// } -// } - -// late Function(AnimationStatus) _getStatusListenerCallBack = (status) { -// if (status == AnimationStatus.completed || -// (status == AnimationStatus.dismissed && -// _isCycle && -// !_skipDismissStatus)) { -// if (_repeatCount == 1) { -// if (animator.endAnimationListener != null) { -// animator.endAnimationListener!(this); -// } -// _repeatCount = _setRepeatCount(animator.repeats, animator.cycles); -// // if (animator.animatorKey == null && -// // animator.resetAnimationOnRebuild != true) { -// // _controller?.dispose(); -// // }//TODO what if remove me -// } else { -// if (status == AnimationStatus.completed) { -// if (_repeatCount > 1) _repeatCount--; -// if (_isCycle) { -// controller.reverse(); -// } else { -// controller -// ..value = 0 -// ..forward(); -// } -// } else if (status == AnimationStatus.dismissed) { -// if (_repeatCount > 1) _repeatCount--; -// controller.forward(); -// } -// } -// } -// }; -// } - -// int _setRepeatCount(int? repeats, int? cycles) { -// return repeats == null ? cycles ?? 1 : repeats; -// } diff --git a/lib/src/child.dart b/lib/src/child.dart index 69c9d6f..4bb0817 100644 --- a/lib/src/child.dart +++ b/lib/src/child.dart @@ -1,66 +1,66 @@ -part of 'animator.dart'; +// part of 'animator.dart'; -///Use Child in combination of other widget listeners, to control -///the part of the widget tree to rebuild. -class Child extends StatelessWidget { - ///Returns widget that is intended to rebuild. - ///It exposes the defined child widget. - final Widget Function(Widget child) builder; +// ///Use Child in combination of other widget listeners, to control +// ///the part of the widget tree to rebuild. +// class Child extends StatelessWidget { +// ///Returns widget that is intended to rebuild. +// ///It exposes the defined child widget. +// final Widget Function(Widget child) builder; - ///Widget that is not intended tor rebuild. - final Widget child; +// ///Widget that is not intended tor rebuild. +// final Widget child; - const Child({ - required this.builder, - Key? key, - required this.child, - }) : super(key: key); - @override - Widget build(BuildContext context) { - return builder(child); - } -} +// const Child({ +// required this.builder, +// Key? key, +// required this.child, +// }) : super(key: key); +// @override +// Widget build(BuildContext context) { +// return builder(child); +// } +// } -class Child2 extends StatelessWidget { - ///Returns widget that is intended to rebuild. - ///It exposes the defined child widget. - final Widget Function(Widget child1, Widget child2) builder; +// class Child2 extends StatelessWidget { +// ///Returns widget that is intended to rebuild. +// ///It exposes the defined child widget. +// final Widget Function(Widget child1, Widget child2) builder; - ///Widget that is not intended tor rebuild. - final Widget child1; - final Widget child2; +// ///Widget that is not intended tor rebuild. +// final Widget child1; +// final Widget child2; - const Child2({ - required this.builder, - Key? key, - required this.child1, - required this.child2, - }) : super(key: key); - @override - Widget build(BuildContext context) { - return builder(child1, child2); - } -} +// const Child2({ +// required this.builder, +// Key? key, +// required this.child1, +// required this.child2, +// }) : super(key: key); +// @override +// Widget build(BuildContext context) { +// return builder(child1, child2); +// } +// } -class Child3 extends StatelessWidget { - ///Returns widget that is intended to rebuild. - ///It exposes the defined child widget. - final Widget Function(Widget child1, Widget child2, Widget child3) builder; +// class Child3 extends StatelessWidget { +// ///Returns widget that is intended to rebuild. +// ///It exposes the defined child widget. +// final Widget Function(Widget child1, Widget child2, Widget child3) builder; - ///Widget that is not intended tor rebuild. - final Widget child1; - final Widget child2; - final Widget child3; +// ///Widget that is not intended tor rebuild. +// final Widget child1; +// final Widget child2; +// final Widget child3; - const Child3({ - required this.builder, - Key? key, - required this.child1, - required this.child2, - required this.child3, - }) : super(key: key); - @override - Widget build(BuildContext context) { - return builder(child1, child2, child3); - } -} +// const Child3({ +// required this.builder, +// Key? key, +// required this.child1, +// required this.child2, +// required this.child3, +// }) : super(key: key); +// @override +// Widget build(BuildContext context) { +// return builder(child1, child2, child3); +// } +// } diff --git a/pubspec.yaml b/pubspec.yaml index 3f961a8..58c8016 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,14 +2,13 @@ name: animator description: A Flutter library that makes animation easer. It allows for separation of animation setup from the User Interface. version: 3.1.0 homepage: https://github.com/GIfatahTH/animator -publish_to: none environment: sdk: ">=2.12.0 <3.0.0" dependencies: flutter: sdk: flutter - states_rebuilder: ^4.3.0-beta+1 + states_rebuilder: ^4.3.0 dev_dependencies: flutter_test: diff --git a/test/implicite_animator_test.dart b/test/animate_widget_test.dart similarity index 90% rename from test/implicite_animator_test.dart rename to test/animate_widget_test.dart index c237a2a..63eaf82 100644 --- a/test/implicite_animator_test.dart +++ b/test/animate_widget_test.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:animator/animator.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -1277,4 +1279,137 @@ void main() { expect(outVal, 0); }, ); + testWidgets( + 'WHEN triggerOnRebuild is true' + 'THEN the animation start when AnimateWidget is rebuild', + (tester) async { + final model = false.inj(); + int value = 0; + await tester.pumpWidget(On( + () => AnimateWidget( + duration: Duration(seconds: 1), + triggerOnInit: false, + triggerOnRebuild: true, + repeats: model.state ? 1 : 0, + builder: (_, animate) { + value = animate + .fromTween((currentValue) => IntTween(begin: 0, end: 10))!; + return Container(); + }, + ), + ).listenTo(model)); + expect(value, 0); + await tester.pumpAndSettle(); + expect(value, 0); + model.state = true; + expect(value, 0); + await tester.pumpAndSettle(); + expect(value, 10); + }, + ); + + testWidgets( + 'WHEN resetOnRebuild is true' + 'THEN the animation start when AnimateWidget is rebuild', + (tester) async { + final model = false.inj(); + int value = 0; + await tester.pumpWidget(On( + () => AnimateWidget( + duration: Duration(seconds: 1), + triggerOnInit: true, + resetOnRebuild: true, + cycles: model.state ? 1 : 1, + builder: (_, animate) { + value = animate + .fromTween((currentValue) => IntTween(begin: 0, end: 10))!; + return Container(); + }, + ), + ).listenTo(model)); + expect(value, 0); + await tester.pumpAndSettle(); + expect(value, 10); + model.state = true; + await tester.pump(); + expect(value, 0); + await tester.pumpAndSettle(); + expect(value, 10); + }, + ); + + testWidgets( + 'WHEN resetOnRebuild is true' + 'THEN the animation start when AnimateWidget is rebuild1', + (tester) async { + final model = false.inj(); + int value = 0; + await tester.pumpWidget(On( + () => AnimateWidget( + duration: Duration(seconds: 1), + reverseCurve: model.state ? Curves.bounceIn : null, + reverseDuration: model.state ? Duration(seconds: 2) : null, + triggerOnInit: false, + resetOnRebuild: true, + cycles: model.state ? 1 : 0, + builder: (_, animate) { + value = animate + .fromTween((currentValue) => IntTween(begin: 0, end: 10))!; + return Container(); + }, + ), + ).listenTo(model)); + expect(value, 0); + await tester.pumpAndSettle(); + expect(value, 0); + model.state = true; + await tester.pump(); + expect(value, 0); + await tester.pump(Duration(milliseconds: 100)); + await tester.pump(Duration(seconds: 1)); + await tester.pumpAndSettle(); + expect(value, 10); + }, + ); + + testWidgets( + 'WHEN resetOnRebuild is true', + (tester) async { + final model = false.inj(); + int value = 0; + var _animate; + await tester.pumpWidget(On( + () => AnimateWidget( + duration: Duration(seconds: 1), + triggerOnInit: false, + resetOnRebuild: true, + cycles: 2, + builder: (_, animate) { + _animate = animate; + value = animate + .setCurve(Curves.bounceIn) + .setReverseCurve(Curves.ease) + .fromTween((currentValue) => IntTween(begin: 0, end: 10))!; + return Container(); + }, + ), + ).listenTo(model)); + expect(value, 0); + print(_animate.curvedAnimation); + await tester.pumpAndSettle(); + expect(value, 0); + model.state = true; + await tester.pump(); + expect(value, 0); + await tester.pump(Duration(seconds: 1)); + expect(value, 10); + await tester.pump(Duration(milliseconds: 100)); + await tester.pump(Duration(milliseconds: 100)); + expect(_animate.controller.duration, Duration(seconds: 1)); + expect(_animate.curvedAnimation.toString().endsWith('(◀ 0.900)➩_Linear'), + true); + await tester.pump(Duration(seconds: 1)); + expect(value, 0); + }, + ); } diff --git a/test/animator_map_test.dart b/test/animator_map_test.dart index 1e3ed96..9bfae27 100644 --- a/test/animator_map_test.dart +++ b/test/animator_map_test.dart @@ -434,7 +434,10 @@ void main() { Offset? animationValue2; AnimationStatus? animationStatue; var numberOfRepeats = 0; - final animatorKey = AnimatorKey(); + final animatorKey = AnimatorKey(initialMapValue: { + 'anim1': 0, + 'anim2': Offset.zero, + }); final animator = Animator( tweenMap: { 'anim1': Tween(begin: 0, end: 1), @@ -458,10 +461,12 @@ void main() { expect(animationValue2, isNull); expect(animationStatue, isNull); + expect(animatorKey.getValue('anim1'), equals(0)); + expect(animatorKey.getValue('anim2'), equals(Offset.zero)); await tester.pumpWidget(animator); - expect(animationValue1, equals(0)); expect(animationValue2, equals(Offset.zero)); + expect(animatorKey.animation, isA()); animatorKey.triggerAnimation(); await tester.pump(); expect(animationStatue, equals(AnimationStatus.forward)); diff --git a/test/animator_test.dart b/test/animator_test.dart index 7f3db82..fa5c3ce 100644 --- a/test/animator_test.dart +++ b/test/animator_test.dart @@ -862,6 +862,44 @@ void main() { }, ); + testWidgets( + 'online change of animation setup, using refreshAnimation' + 'Using tweenMap', + (WidgetTester tester) async { + Offset? offset; + + final animatorKey = AnimatorKey(); + await tester.pumpWidget(Animator( + tweenMap: { + 'tween': Tween(begin: Offset.zero, end: const Offset(1, 1)) + }, + duration: const Duration(seconds: 1), + animatorKey: animatorKey, + builder: (_, anim, __) { + offset = anim.getValue('tween'); + return Container(); + }, + )); + + expect(offset, equals(Offset.zero)); + animatorKey.triggerAnimation(); + await tester.pumpAndSettle(); + expect(offset, const Offset(1, 1)); + + animatorKey.resetAnimation( + tweenMap: { + 'tween': Tween( + begin: const Offset(10, 10), end: const Offset(20, 20)) + }, + curve: Curves.bounceIn, + ); + await tester.pump(); + expect(offset, const Offset(10, 10)); + await tester.pumpAndSettle(); + expect(offset, const Offset(20, 20)); + }, + ); + // testWidgets( // 'should throw if both tween and tweenMap are defined', // (WidgetTester tester) async {