From 9f4bdd3787a6009ce3262993ab6c867c11b14c20 Mon Sep 17 00:00:00 2001 From: Shawn Date: Fri, 28 Oct 2022 21:32:40 -0600 Subject: [PATCH 01/11] Upgrade to 2.17 for better constructors --- pubspec.lock | 13 +++---------- pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 7708595..0555ac7 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -60,13 +60,6 @@ packages: description: flutter source: sdk version: "0.0.0" - js: - dependency: transitive - description: - name: js - url: "https://pub.dartlang.org" - source: hosted - version: "0.6.4" lints: dependency: transitive description: @@ -148,14 +141,14 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.14" + version: "0.4.12" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "2.1.2" sdks: - dart: ">=2.18.0 <3.0.0" + dart: ">=2.17.0 <3.0.0" flutter: ">=1.17.0" diff --git a/pubspec.yaml b/pubspec.yaml index ab91402..a40011f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ repository: https://github.com/gskinner/flutter_animate issue_tracker: https://github.com/gskinner/flutter_animate/issues environment: - sdk: ">=2.15.0 <3.0.0" + sdk: ">=2.17.0 <3.0.0" flutter: ">=1.17.0" dependencies: From 1b0ffeb433f3cceb83adf92c96dc10cc13069526 Mon Sep 17 00:00:00 2001 From: Shawn Date: Fri, 28 Oct 2022 21:36:25 -0600 Subject: [PATCH 02/11] Add some initial Slide and Fade variations, enough to show basic composition / architecture Add CompositeEffect helper class, and composeEffects helper method Tweak expectWidgetWithDouble method to be less strict --- lib/effects/effect.dart | 34 ++++++++++++++++----- lib/effects/effects.dart | 4 +++ lib/effects/fade_effect.dart | 32 -------------------- lib/effects/variations/fade_in.dart | 38 +++++++++++++++++++++++ lib/effects/variations/fade_out.dart | 40 +++++++++++++++++++++++++ lib/effects/variations/slide_in.dart | 27 +++++++++++++++++ lib/effects/variations/slide_out.dart | 27 +++++++++++++++++ test/effects/variations/fade_test.dart | 27 +++++++++++++++++ test/effects/variations/slide_test.dart | 17 +++++++++++ test/tester_extensions.dart | 2 +- 10 files changed, 208 insertions(+), 40 deletions(-) create mode 100644 lib/effects/variations/fade_in.dart create mode 100644 lib/effects/variations/fade_out.dart create mode 100644 lib/effects/variations/slide_in.dart create mode 100644 lib/effects/variations/slide_out.dart create mode 100644 test/effects/variations/fade_test.dart create mode 100644 test/effects/variations/slide_test.dart diff --git a/lib/effects/effect.dart b/lib/effects/effect.dart index 79576ba..8df8b59 100644 --- a/lib/effects/effect.dart +++ b/lib/effects/effect.dart @@ -2,6 +2,19 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import '../flutter_animate.dart'; +/// An Effect that is composed of or more other existing Effects. Provides +/// syntactic sugar for calling the `composeEffects` method. +abstract class CompositeEffect extends Effect { + const CompositeEffect({super.delay, super.duration, super.curve}); + + @protected + List get effects; + + @override + Widget build(BuildContext context, Widget child, AnimationController controller, EffectEntry entry) => + composeEffects(effects, context, child, controller, entry); +} + /// Class that defines the required interface and helper methods for /// all effect classes. Look at the various effects for examples of how /// to build new reusable effects. One-off effects can be implemented with @@ -10,6 +23,8 @@ import '../flutter_animate.dart'; /// It can be instantiated and added to Animate, but has no visual effect. @immutable class Effect { + const Effect({this.delay, this.duration, this.curve, this.begin, this.end}); + /// The specified delay for the effect. If null, will use the delay from the /// previous effect, or [Duration.zero] if this is the first effect. final Duration? delay; @@ -30,8 +45,6 @@ class Effect { /// default value when appropriate. final T? end; - const Effect({this.delay, this.duration, this.curve, this.begin, this.end}); - /// Builds the widgets necessary to implement the effect, based on the /// provided [AnimationController] and [EffectEntry]. Widget build( @@ -48,9 +61,17 @@ class Effect { AnimationController controller, EffectEntry entry, ) { - return entry - .buildAnimation(controller) - .drive(Tween(begin: begin, end: end)); + return entry.buildAnimation(controller).drive(Tween(begin: begin, end: end)); + } + + /// Calls build on one or more effects, composing them together and returning the resulting widget tree + @protected + Widget composeEffects( + List effects, BuildContext context, Widget child, AnimationController controller, EffectEntry entry) { + for (var f in effects) { + child = f.build(context, child, controller, entry); + } + return child; } /// Returns a ratio corresponding to the beginning of the specified entry. @@ -68,8 +89,7 @@ class Effect { /// Check if the animation is currently running / active. bool isAnimationActive(Animation animation) { AnimationStatus status = animation.status; - return status == AnimationStatus.forward || - status == AnimationStatus.reverse; + return status == AnimationStatus.forward || status == AnimationStatus.reverse; } /// Returns an optimized [AnimatedBuilder] that doesn't diff --git a/lib/effects/effects.dart b/lib/effects/effects.dart index 591148e..4217685 100644 --- a/lib/effects/effects.dart +++ b/lib/effects/effects.dart @@ -19,3 +19,7 @@ export 'then_effect.dart'; export 'tint_effect.dart'; export 'toggle_effect.dart'; export 'visibility_effect.dart'; +export 'variations/fade_in.dart'; +export 'variations/fade_out.dart'; +export 'variations/slide_in.dart'; +export 'variations/slide_out.dart'; diff --git a/lib/effects/fade_effect.dart b/lib/effects/fade_effect.dart index 3363236..0828b2b 100644 --- a/lib/effects/fade_effect.dart +++ b/lib/effects/fade_effect.dart @@ -53,36 +53,4 @@ extension FadeEffectExtensions on AnimateManager { begin: begin, end: end, )); - - /// Adds a [fadeIn] extension to [AnimateManager] ([Animate] and [AnimateList]). - /// This is identical to the [fade] extension, except it always uses `end=1.0`. - T fadeIn({ - Duration? delay, - Duration? duration, - Curve? curve, - double? begin, - }) => - addEffect(FadeEffect( - delay: delay, - duration: duration, - curve: curve, - begin: begin ?? FadeEffect.defaultValue, - end: 1.0, - )); - - /// Adds a [fadeOut] extension to [AnimateManager] ([Animate] and [AnimateList]). - /// This is identical to the [fade] extension, except it always uses `end=0.0`. - T fadeOut({ - Duration? delay, - Duration? duration, - Curve? curve, - double? begin, - }) => - addEffect(FadeEffect( - delay: delay, - duration: duration, - curve: curve, - begin: begin ?? FadeEffect.neutralValue, - end: 0.0, - )); } diff --git a/lib/effects/variations/fade_in.dart b/lib/effects/variations/fade_in.dart new file mode 100644 index 0000000..b44af52 --- /dev/null +++ b/lib/effects/variations/fade_in.dart @@ -0,0 +1,38 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_animate/effects/variations/slide_in.dart'; + +import '../../flutter_animate.dart'; + +@immutable +class FadeInEffect extends CompositeEffect { + const FadeInEffect({super.delay, super.duration, super.curve}); + + @override + List get effects => const [FadeEffect(begin: 0, end: 1)]; +} + +@immutable +class FadeInUpEffect extends CompositeEffect { + const FadeInUpEffect({this.beginY, super.delay, super.duration, super.curve}); + + final double? beginY; + + @override + List get effects => [ + const FadeInEffect(), + SlideInUpEffect(beginY: beginY), + ]; +} + +/// TODO: +/// FadeInDown +/// FadeInLeft +/// FadeInRight + +extension FadeInEffectExtensions on AnimateManager { + T fadeIn({Duration? delay, Duration? duration, Curve? curve}) => + addEffect(FadeInEffect(delay: delay, duration: duration, curve: curve)); + + T fadeInUp({double? beginY, Duration? delay, Duration? duration, Curve? curve}) => + addEffect(FadeInUpEffect(beginY: beginY, delay: delay, duration: duration, curve: curve)); +} diff --git a/lib/effects/variations/fade_out.dart b/lib/effects/variations/fade_out.dart new file mode 100644 index 0000000..89a298e --- /dev/null +++ b/lib/effects/variations/fade_out.dart @@ -0,0 +1,40 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_animate/effects/variations/slide_out.dart'; + +import '../../flutter_animate.dart'; + +@immutable +class FadeOutEffect extends CompositeEffect { + const FadeOutEffect({super.delay, super.duration, super.curve}); + + @override + List get effects => const [FadeEffect(begin: 1, end: 0)]; +} + +@immutable +class FadeOutUpEffect extends CompositeEffect { + const FadeOutUpEffect({this.endY, super.delay, super.duration, super.curve}); + + final double? endY; + + @override + List get effects => [ + const FadeOutEffect(), + SlideOutUpEffect(endY: endY), + ]; +} + +/* +TODO: +FadeOutDown +FadeOutLeft +FadeOutRight +*/ + +extension FadeOutEffectExtensions on AnimateManager { + T fadeOut({Duration? delay, Duration? duration, Curve? curve}) => + addEffect(FadeOutEffect(delay: delay, duration: duration, curve: curve)); + + T fadeOutUp({double? endY, Duration? delay, Duration? duration, Curve? curve}) => + addEffect(FadeOutUpEffect(endY: endY, delay: delay, duration: duration, curve: curve)); +} diff --git a/lib/effects/variations/slide_in.dart b/lib/effects/variations/slide_in.dart new file mode 100644 index 0000000..1ce252e --- /dev/null +++ b/lib/effects/variations/slide_in.dart @@ -0,0 +1,27 @@ +import 'package:flutter/widgets.dart'; + +import '../../flutter_animate.dart'; + +@immutable +class SlideInUpEffect extends CompositeEffect { + const SlideInUpEffect({this.beginY, super.delay, super.duration, super.curve}); + static const defaultBeginY = -.2; + final double? beginY; + + @override + List get effects => [ + SlideEffect(begin: Offset(0, beginY ?? defaultBeginY), end: Offset.zero), + ]; +} + +/* +TODO: +SlideInDown +SlideInLeft +SlideInRight +*/ + +extension SlideInExtensions on AnimateManager { + T slideInUp({double? beginY, Duration? delay, Duration? duration, Curve? curve}) => + addEffect(SlideInUpEffect(beginY: beginY, delay: delay, duration: duration, curve: curve)); +} diff --git a/lib/effects/variations/slide_out.dart b/lib/effects/variations/slide_out.dart new file mode 100644 index 0000000..f50c574 --- /dev/null +++ b/lib/effects/variations/slide_out.dart @@ -0,0 +1,27 @@ +import 'package:flutter/widgets.dart'; + +import '../../flutter_animate.dart'; + +@immutable +class SlideOutUpEffect extends CompositeEffect { + const SlideOutUpEffect({this.endY, super.delay, super.duration, super.curve}); + static const defaultEndY = .2; + final double? endY; + + @override + List get effects => [ + SlideEffect(begin: Offset.zero, end: Offset(0, endY ?? defaultEndY)), + ]; +} + +/* +TODO: +SlideOutDown +SlideOutLeft +SlideOutRight +*/ + +extension SlideOutExtensions on AnimateManager { + T slideOutUp({double? endY, Duration? delay, Duration? duration, Curve? curve}) => + addEffect(SlideOutUpEffect(endY: endY, delay: delay, duration: duration, curve: curve)); +} diff --git a/test/effects/variations/fade_test.dart b/test/effects/variations/fade_test.dart new file mode 100644 index 0000000..3b7eca0 --- /dev/null +++ b/test/effects/variations/fade_test.dart @@ -0,0 +1,27 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_animate/flutter_animate.dart'; + +import '../../tester_extensions.dart'; + +void main() { + testWidgets('fade variations', (tester) async { + final fadeIn = const FlutterLogo().animate().fadeIn(duration: 1.seconds); + await tester.pumpAnimation(fadeIn, initialDelay: 750.ms); + tester.expectWidgetWithDouble((ft) => ft.opacity.value, .75, 'opacity'); + + final fadeInUp = const FlutterLogo().animate(key: const ValueKey(1)).fadeInUp(duration: 1.seconds, beginY: -1); + await tester.pumpAnimation(fadeInUp, initialDelay: 750.ms); + tester.expectWidgetWithDouble((ft) => ft.opacity.value, .75, 'opacity'); + tester.expectWidgetWithDouble((ft) => ft.position.value.dy, -.25, 'slide'); + + final fadeOut = const FlutterLogo().animate(key: const ValueKey(2)).fadeOut(duration: 1.seconds); + await tester.pumpAnimation(fadeOut, initialDelay: 750.ms); + tester.expectWidgetWithDouble((ft) => ft.opacity.value, .25, 'opacity'); + + final fadeOutUp = const FlutterLogo().animate(key: const ValueKey(3)).fadeOutUp(duration: 1.seconds, endY: 1); + await tester.pumpAnimation(fadeOutUp, initialDelay: 750.ms); + tester.expectWidgetWithDouble((ft) => ft.opacity.value, .25, 'opacity'); + tester.expectWidgetWithDouble((ft) => ft.position.value.dy, .75, 'slide'); + }); +} diff --git a/test/effects/variations/slide_test.dart b/test/effects/variations/slide_test.dart new file mode 100644 index 0000000..4747084 --- /dev/null +++ b/test/effects/variations/slide_test.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_animate/flutter_animate.dart'; + +import '../../tester_extensions.dart'; + +void main() { + testWidgets('slide variations', (tester) async { + final slideInUp = const FlutterLogo().animate().slideInUp(duration: 1.seconds, beginY: -1); + await tester.pumpAnimation(slideInUp, initialDelay: 750.ms); + tester.expectWidgetWithDouble((ft) => ft.position.value.dy, -.25, 'slide'); + + final slideOutUp = const FlutterLogo().animate(key: const ValueKey(1)).slideOutUp(duration: 1.seconds, endY: 1); + await tester.pumpAnimation(slideOutUp, initialDelay: 750.ms); + tester.expectWidgetWithDouble((ft) => ft.position.value.dy, .75, 'slide'); + }); +} diff --git a/test/tester_extensions.dart b/test/tester_extensions.dart index 498e92a..16f6778 100644 --- a/test/tester_extensions.dart +++ b/test/tester_extensions.dart @@ -22,7 +22,7 @@ extension TesterExtensions on WidgetTester { }) { expect( widget(findFirst ? find.byType(T).first : find.byType(T).last), - isA().having((t) => getValue(t), debugTitle, expectedValue), + isA().having((t) => (getValue(t) - expectedValue).abs() < .00000001, debugTitle, true), ); } From f77eeef0398c4341b38b741022f8145f273c4dc7 Mon Sep 17 00:00:00 2001 From: Shawn Date: Wed, 9 Nov 2022 12:49:46 -0700 Subject: [PATCH 03/11] Begin work on BlurX, which changes the underlying type of effect. Its a composite tween that changes the underlying type, which is not currently supported cleanly. --- lib/effects/variations/blur.dart | 42 ++++++++++++++++++++++++++++ lib/effects/variations/fade_out.dart | 1 - 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 lib/effects/variations/blur.dart diff --git a/lib/effects/variations/blur.dart b/lib/effects/variations/blur.dart new file mode 100644 index 0000000..8eb5948 --- /dev/null +++ b/lib/effects/variations/blur.dart @@ -0,0 +1,42 @@ +// ignore_for_file: overridden_fields + +import 'package:flutter/widgets.dart'; + +import '../../flutter_animate.dart'; + +//TODO: Impplement this without needing to override begin/end +@immutable +class BlurXEffect extends CompositeEffect { + const BlurXEffect({this.begin, this.end, super.delay, super.duration, super.curve}); + + @override + final double? begin; + + @override + final double? end; + + @override + List get effects => [ + BlurEffect( + begin: Offset(begin ?? BlurEffect.neutralBlur, 0), + end: Offset(end ?? (begin == null ? BlurEffect.defaultBlur : BlurEffect.neutralBlur), 0), + ) + ]; +} + +extension BlurEffectExtensions on AnimateManager { + T blurX({ + Duration? delay, + Duration? duration, + Curve? curve, + double? begin, + double? end, + }) => + addEffect(BlurXEffect(delay: delay, duration: duration, curve: curve)); +} + + +/// TODO: +/// FadeInDown +/// FadeInLeft +/// FadeInRight \ No newline at end of file diff --git a/lib/effects/variations/fade_out.dart b/lib/effects/variations/fade_out.dart index 89a298e..5b90699 100644 --- a/lib/effects/variations/fade_out.dart +++ b/lib/effects/variations/fade_out.dart @@ -1,5 +1,4 @@ import 'package:flutter/widgets.dart'; -import 'package:flutter_animate/effects/variations/slide_out.dart'; import '../../flutter_animate.dart'; From b4463a844664cc627f1e1c5d138d1cba14eb0134 Mon Sep 17 00:00:00 2001 From: Shawn Date: Wed, 9 Nov 2022 14:08:29 -0700 Subject: [PATCH 04/11] Add BeginEnd tween and CompositeTweenMixin --- example/pubspec.lock | 13 ++---- lib/animate.dart | 13 +++--- lib/animate_list.dart | 9 ++--- lib/effects/blur_effect.dart | 2 +- lib/effects/callback_effect.dart | 2 +- lib/effects/custom_effect.dart | 4 +- lib/effects/effect.dart | 58 ++++++++++++++++++--------- lib/effects/fade_effect.dart | 2 +- lib/effects/flip_effect.dart | 2 +- lib/effects/listen_effect.dart | 2 +- lib/effects/move_effect.dart | 2 +- lib/effects/rotate_effect.dart | 2 +- lib/effects/saturate_effect.dart | 2 +- lib/effects/scale_effect.dart | 11 ++--- lib/effects/shake_effect.dart | 2 +- lib/effects/shimmer_effect.dart | 2 +- lib/effects/slide_effect.dart | 2 +- lib/effects/swap_effect.dart | 2 +- lib/effects/then_effect.dart | 6 +-- lib/effects/tint_effect.dart | 2 +- lib/effects/toggle_effect.dart | 2 +- lib/effects/variations/blur.dart | 18 +++------ lib/effects/variations/fade_in.dart | 6 +-- lib/effects/variations/fade_out.dart | 2 +- lib/effects/variations/slide_in.dart | 2 +- lib/effects/variations/slide_out.dart | 2 +- lib/effects/visibility_effect.dart | 5 +-- lib/flutter_animate.dart | 6 +-- 28 files changed, 88 insertions(+), 95 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 09a811e..3964be8 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -74,13 +74,6 @@ packages: description: flutter source: sdk version: "0.0.0" - js: - dependency: transitive - description: - name: js - url: "https://pub.dartlang.org" - source: hosted - version: "0.6.4" lints: dependency: transitive description: @@ -162,14 +155,14 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.14" + version: "0.4.12" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "2.1.2" sdks: - dart: ">=2.18.0 <3.0.0" + dart: ">=2.17.1 <3.0.0" flutter: ">=1.17.0" diff --git a/lib/animate.dart b/lib/animate.dart index d68f6f1..ba1abf7 100644 --- a/lib/animate.dart +++ b/lib/animate.dart @@ -134,7 +134,7 @@ class Animate extends StatefulWidget with AnimateManager { /// ``` final AnimateCallback? onPlay; - /// Defines a delay before the animation is started. Unlike [Effect.delay], + /// Defines a delay before the animation is started. Unlike [BeginEndEffect.delay], /// this is not a part of the overall animation, and only runs once if the /// animation is looped. [onPlay] is called after this delay. final Duration delay; @@ -163,16 +163,14 @@ class Animate extends StatefulWidget with AnimateManager { @override State createState() => _AnimateState(); - /// Adds an effect. This is mostly used by [Effect] extension methods to append effects + /// Adds an effect. This is mostly used by [BeginEndEffect] extension methods to append effects /// to an [Animate] instance. @override Animate addEffect(Effect effect) { EffectEntry? prior = _lastEntry; Duration delay = (effect is ThenEffect) - ? (effect.delay ?? Duration.zero) + - (prior?.delay ?? Duration.zero) + - (prior?.duration ?? Duration.zero) + ? (effect.delay ?? Duration.zero) + (prior?.delay ?? Duration.zero) + (prior?.duration ?? Duration.zero) : effect.delay ?? prior?.delay ?? Duration.zero; EffectEntry entry = EffectEntry( @@ -205,8 +203,7 @@ class _AnimateState extends State with SingleTickerProviderStateMixin { @override void didUpdateWidget(Animate oldWidget) { - if (oldWidget.controller != widget.controller || - oldWidget._duration != widget._duration) { + if (oldWidget.controller != widget.controller || oldWidget._duration != widget._duration) { _initController(); _play(); } else if (oldWidget.adapter != widget.adapter) { @@ -287,7 +284,7 @@ class _AnimateState extends State with SingleTickerProviderStateMixin { extension AnimateWidgetExtensions on Widget { Animate animate({ Key? key, - List? effects, + List? effects, AnimateCallback? onComplete, AnimateCallback? onPlay, Duration delay = Duration.zero, diff --git a/lib/animate_list.dart b/lib/animate_list.dart index 5d81933..392c109 100644 --- a/lib/animate_list.dart +++ b/lib/animate_list.dart @@ -29,8 +29,7 @@ import 'flutter_animate.dart'; /// ) /// ) /// ``` -class AnimateList extends ListBase - with AnimateManager { +class AnimateList extends ListBase with AnimateManager { /// Specifies a default interval to use for new `AnimateList` instances. static Duration defaultInterval = Duration.zero; @@ -47,7 +46,7 @@ class AnimateList extends ListBase /// instance, and proxy any added effects to each of them. AnimateList({ required List children, - List? effects, + List? effects, Duration? interval, AnimateCallback? onPlay, AnimateCallback? onComplete, @@ -76,7 +75,7 @@ class AnimateList extends ListBase final List _widgets = []; final List _managers = []; - /// Adds an effect. This is mostly used by [Effect] extension methods to + /// Adds an effect. This is mostly used by [BeginEndEffect] extension methods to /// append effects to an [AnimateList] instance. @override AnimateList addEffect(Effect effect) { @@ -108,7 +107,7 @@ class AnimateList extends ListBase /// Ex. `[foo, bar].animate()` is equivalent to `AnimateList(children: [foo, bar])`. extension AnimateListExtensions on List { AnimateList animate({ - List? effects, + List? effects, Duration? interval, AnimateCallback? onPlay, AnimateCallback? onComplete, diff --git a/lib/effects/blur_effect.dart b/lib/effects/blur_effect.dart index 1e8c61d..34deada 100644 --- a/lib/effects/blur_effect.dart +++ b/lib/effects/blur_effect.dart @@ -6,7 +6,7 @@ import '../flutter_animate.dart'; /// Effect that animates a blur on the target (via [ImageFiltered]) /// between the specified begin and end blur radius values. Defaults to a blur radius of `begin=0, end=4`. @immutable -class BlurEffect extends Effect { +class BlurEffect extends BeginEndEffect { static const Offset neutralValue = Offset(neutralBlur, neutralBlur); static const Offset defaultValue = Offset(defaultBlur, defaultBlur); diff --git a/lib/effects/callback_effect.dart b/lib/effects/callback_effect.dart index 472c576..b481a28 100644 --- a/lib/effects/callback_effect.dart +++ b/lib/effects/callback_effect.dart @@ -27,7 +27,7 @@ import '../flutter_animate.dart'; /// an animation that is driven by an [Adapter] (or manipulated via its controller) /// may behave unexpectedly in certain circumstances. @immutable -class CallbackEffect extends Effect { +class CallbackEffect extends BeginEndEffect { const CallbackEffect({ Duration? delay, Duration? duration, diff --git a/lib/effects/custom_effect.dart b/lib/effects/custom_effect.dart index 68d5544..315dbc7 100644 --- a/lib/effects/custom_effect.dart +++ b/lib/effects/custom_effect.dart @@ -11,9 +11,9 @@ import '../flutter_animate.dart'; /// ``` /// /// Note that the above could also be accomplished by creating a custom effect class -/// that extends [Effect] and utilizes [AnimatedPadding]. +/// that extends [BeginEndEffect] and utilizes [AnimatedPadding]. @immutable -class CustomEffect extends Effect { +class CustomEffect extends BeginEndEffect { const CustomEffect({ required this.builder, Duration? delay, diff --git a/lib/effects/effect.dart b/lib/effects/effect.dart index 8df8b59..72d3847 100644 --- a/lib/effects/effect.dart +++ b/lib/effects/effect.dart @@ -15,6 +15,35 @@ abstract class CompositeEffect extends Effect { composeEffects(effects, context, child, controller, entry); } +mixin CompositeEffectMixin on Effect { + List get effects; + + @override + Widget build(BuildContext context, Widget child, AnimationController controller, EffectEntry entry) => + composeEffects(effects, context, child, controller, entry); +} + +/// Adds a begin/end fields and a convenience method for passing them to entry.buildAnimation() +class BeginEndEffect extends Effect { + const BeginEndEffect({super.delay, super.duration, super.curve, this.begin, this.end}); + + /// The begin value for the effect. If null, effects should use a reasonable + /// default value when appropriate. + final T? begin; + + /// The end value for the effect. If null, effects should use a reasonable + /// default value when appropriate. + final T? end; + + /// Returns an animation based on the controller, entry, and begin/end values. + Animation buildAnimation( + AnimationController controller, + EffectEntry entry, + ) { + return entry.buildAnimation(controller).drive(Tween(begin: begin, end: end)); + } +} + /// Class that defines the required interface and helper methods for /// all effect classes. Look at the various effects for examples of how /// to build new reusable effects. One-off effects can be implemented with @@ -22,8 +51,8 @@ abstract class CompositeEffect extends Effect { /// /// It can be instantiated and added to Animate, but has no visual effect. @immutable -class Effect { - const Effect({this.delay, this.duration, this.curve, this.begin, this.end}); +abstract class Effect { + const Effect({this.delay, this.duration, this.curve}); /// The specified delay for the effect. If null, will use the delay from the /// previous effect, or [Duration.zero] if this is the first effect. @@ -37,14 +66,6 @@ class Effect { /// previous effect, or [Animate.defaultCurve] if this is the first effect. final Curve? curve; - /// The begin value for the effect. If null, effects should use a reasonable - /// default value when appropriate. - final T? begin; - - /// The end value for the effect. If null, effects should use a reasonable - /// default value when appropriate. - final T? end; - /// Builds the widgets necessary to implement the effect, based on the /// provided [AnimationController] and [EffectEntry]. Widget build( @@ -56,18 +77,15 @@ class Effect { return child; } - /// Returns an animation based on the controller, entry, and begin/end values. - Animation buildAnimation( - AnimationController controller, - EffectEntry entry, - ) { - return entry.buildAnimation(controller).drive(Tween(begin: begin, end: end)); - } - /// Calls build on one or more effects, composing them together and returning the resulting widget tree @protected Widget composeEffects( - List effects, BuildContext context, Widget child, AnimationController controller, EffectEntry entry) { + List effects, + BuildContext context, + Widget child, + AnimationController controller, + EffectEntry entry, + ) { for (var f in effects) { child = f.build(context, child, controller, entry); } @@ -137,7 +155,7 @@ extension EffectExtensions on AnimateManager { double? begin, double? end, }) => - addEffect(Effect( + addEffect(BeginEndEffect( delay: delay, duration: duration, curve: curve, diff --git a/lib/effects/fade_effect.dart b/lib/effects/fade_effect.dart index 0828b2b..78f72a4 100644 --- a/lib/effects/fade_effect.dart +++ b/lib/effects/fade_effect.dart @@ -5,7 +5,7 @@ import '../flutter_animate.dart'; /// Effect that animates the opacity of the target (via [FadeTransition]) between the specified begin and end values. /// It defaults to `begin=0, end=1`. @immutable -class FadeEffect extends Effect { +class FadeEffect extends BeginEndEffect { static const double neutralValue = 1.0; static const double defaultValue = 0.0; diff --git a/lib/effects/flip_effect.dart b/lib/effects/flip_effect.dart index 78dbe0e..878aea9 100644 --- a/lib/effects/flip_effect.dart +++ b/lib/effects/flip_effect.dart @@ -22,7 +22,7 @@ import '../flutter_animate.dart'; /// would cause it to rotate around the Y axis — flipping horizontally. /// Default is [Axis.vertical]. @immutable -class FlipEffect extends Effect { +class FlipEffect extends BeginEndEffect { static const double neutralValue = 0.0; static const double defaultValue = -0.5; diff --git a/lib/effects/listen_effect.dart b/lib/effects/listen_effect.dart index f551796..72a073a 100644 --- a/lib/effects/listen_effect.dart +++ b/lib/effects/listen_effect.dart @@ -27,7 +27,7 @@ import '../flutter_animate.dart'; /// /// See also: [CustomEffect] and [CallbackEffect]. @immutable -class ListenEffect extends Effect { +class ListenEffect extends BeginEndEffect { const ListenEffect({ Duration? delay, Duration? duration, diff --git a/lib/effects/move_effect.dart b/lib/effects/move_effect.dart index fe9bbf2..bf010a2 100644 --- a/lib/effects/move_effect.dart +++ b/lib/effects/move_effect.dart @@ -8,7 +8,7 @@ import '../flutter_animate.dart'; /// /// To specify offsets relative to the target's size, use [SlideEffect]. @immutable -class MoveEffect extends Effect { +class MoveEffect extends BeginEndEffect { static const Offset neutralValue = Offset(neutralMove, neutralMove); static const Offset defaultValue = Offset(neutralMove, defaultMove); diff --git a/lib/effects/rotate_effect.dart b/lib/effects/rotate_effect.dart index 49f371b..535eb16 100644 --- a/lib/effects/rotate_effect.dart +++ b/lib/effects/rotate_effect.dart @@ -10,7 +10,7 @@ import '../flutter_animate.dart'; /// will occur). For example an alignment of [Alignment.topLeft] would rotate around the top left /// corner of the child. @immutable -class RotateEffect extends Effect { +class RotateEffect extends BeginEndEffect { static const double neutralValue = 0.0; static const double defaultValue = -1.0; diff --git a/lib/effects/saturate_effect.dart b/lib/effects/saturate_effect.dart index 3551070..d369055 100644 --- a/lib/effects/saturate_effect.dart +++ b/lib/effects/saturate_effect.dart @@ -13,7 +13,7 @@ import '../flutter_animate.dart'; /// .saturate(duration: 2.seconds) /// ``` @immutable -class SaturateEffect extends Effect { +class SaturateEffect extends BeginEndEffect { static const double neutralValue = 1.0; static const double defaultValue = 0.0; diff --git a/lib/effects/scale_effect.dart b/lib/effects/scale_effect.dart index c318516..263406a 100644 --- a/lib/effects/scale_effect.dart +++ b/lib/effects/scale_effect.dart @@ -5,7 +5,7 @@ import '../flutter_animate.dart'; /// Effect that scales the target (via [ScaleTransition]) between the specified begin and end values. /// Defaults to `begin=0, end=1`. @immutable -class ScaleEffect extends Effect { +class ScaleEffect extends BeginEndEffect { static const Offset neutralValue = Offset(neutralScale, neutralScale); static const Offset defaultValue = Offset(defaultScale, defaultScale); @@ -79,8 +79,7 @@ extension ScaleEffectExtensions on AnimateManager { double? end, Alignment? alignment, }) { - begin ??= - (end == null ? ScaleEffect.defaultScale : ScaleEffect.neutralScale); + begin ??= (end == null ? ScaleEffect.defaultScale : ScaleEffect.neutralScale); end ??= ScaleEffect.neutralScale; return addEffect(ScaleEffect( delay: delay, @@ -102,8 +101,7 @@ extension ScaleEffectExtensions on AnimateManager { double? end, Alignment? alignment, }) { - begin ??= - (end == null ? ScaleEffect.defaultScale : ScaleEffect.neutralScale); + begin ??= (end == null ? ScaleEffect.defaultScale : ScaleEffect.neutralScale); end ??= ScaleEffect.neutralScale; return addEffect(ScaleEffect( delay: delay, @@ -125,8 +123,7 @@ extension ScaleEffectExtensions on AnimateManager { double? end, Alignment? alignment, }) { - begin ??= - (end == null ? ScaleEffect.defaultScale : ScaleEffect.neutralScale); + begin ??= (end == null ? ScaleEffect.defaultScale : ScaleEffect.neutralScale); end ??= ScaleEffect.neutralScale; return addEffect(ScaleEffect( delay: delay, diff --git a/lib/effects/shake_effect.dart b/lib/effects/shake_effect.dart index 8638370..8bd58b3 100644 --- a/lib/effects/shake_effect.dart +++ b/lib/effects/shake_effect.dart @@ -22,7 +22,7 @@ import '../flutter_animate.dart'; /// Text("Hello").animate().shakeX(amount: 10) /// ``` @immutable -class ShakeEffect extends Effect { +class ShakeEffect extends BeginEndEffect { static const int defaultHz = 10; static const double defaultRotation = pi / 36; static const double defaultMove = 6; diff --git a/lib/effects/shimmer_effect.dart b/lib/effects/shimmer_effect.dart index 0d25552..dab89e9 100644 --- a/lib/effects/shimmer_effect.dart +++ b/lib/effects/shimmer_effect.dart @@ -22,7 +22,7 @@ import '../flutter_animate.dart'; /// * [BlendMode.srcOver] layers the gradient fill over the child (no masking) /// * [BlendMode.dstOver] layers the gradient fill under the child (no masking) @immutable -class ShimmerEffect extends Effect { +class ShimmerEffect extends BeginEndEffect { static const Color defaultColor = Color(0x80FFFFFF); static const double defaultSize = 1; static const double defaultAngle = pi / 12; diff --git a/lib/effects/slide_effect.dart b/lib/effects/slide_effect.dart index d3c171a..cccdd88 100644 --- a/lib/effects/slide_effect.dart +++ b/lib/effects/slide_effect.dart @@ -8,7 +8,7 @@ import '../flutter_animate.dart'; /// /// To use pixel offsets instead, use [MoveEffect]. @immutable -class SlideEffect extends Effect { +class SlideEffect extends BeginEndEffect { static const Offset neutralValue = Offset(neutralSlide, neutralSlide); static const Offset defaultValue = Offset(neutralSlide, defaultSlide); diff --git a/lib/effects/swap_effect.dart b/lib/effects/swap_effect.dart index 8a86afc..8930ec0 100644 --- a/lib/effects/swap_effect.dart +++ b/lib/effects/swap_effect.dart @@ -36,7 +36,7 @@ import '../flutter_animate.dart'; /// [AnimationController]. So, for example, repeating the first animation (the /// fade out) via its controller will not affect the second animation (fade in). @immutable -class SwapEffect extends Effect { +class SwapEffect extends BeginEndEffect { const SwapEffect({ Duration? delay, Duration? duration, diff --git a/lib/effects/then_effect.dart b/lib/effects/then_effect.dart index e6ab40f..9f35cfe 100644 --- a/lib/effects/then_effect.dart +++ b/lib/effects/then_effect.dart @@ -28,16 +28,14 @@ import '../flutter_animate.dart'; /// subsequent effect. In the example above, it is functionally equivalent to /// setting `delay: 1400.ms` on the blur effect. @immutable -class ThenEffect extends Effect { +class ThenEffect extends BeginEndEffect { // NOTE: this is just an empty effect, the logic happens in Animate // when it recognizes the type. const ThenEffect({Duration? delay, Duration? duration, Curve? curve}) : super(delay: delay, duration: duration, curve: curve); @override - Widget build(BuildContext context, Widget child, - AnimationController controller, EffectEntry entry) => - child; + Widget build(BuildContext context, Widget child, AnimationController controller, EffectEntry entry) => child; } extension ThenEffectExtensions on AnimateManager { diff --git a/lib/effects/tint_effect.dart b/lib/effects/tint_effect.dart index 200e592..4e9fb7b 100644 --- a/lib/effects/tint_effect.dart +++ b/lib/effects/tint_effect.dart @@ -15,7 +15,7 @@ import '../flutter_animate.dart'; /// .tint(color: Colors.blue, end: 0.5, duration: 2.seconds) /// ``` @immutable -class TintEffect extends Effect { +class TintEffect extends BeginEndEffect { static const double neutralValue = 0.0; static const double defaultValue = 1.0; diff --git a/lib/effects/toggle_effect.dart b/lib/effects/toggle_effect.dart index 079ce49..15e46ca 100644 --- a/lib/effects/toggle_effect.dart +++ b/lib/effects/toggle_effect.dart @@ -20,7 +20,7 @@ import '../flutter_animate.dart'; /// The child of `Animate` is passed through to the builder in the `child` param /// (possibly already wrapped by prior effects). @immutable -class ToggleEffect extends Effect { +class ToggleEffect extends BeginEndEffect { const ToggleEffect({ Duration? delay, Duration? duration, diff --git a/lib/effects/variations/blur.dart b/lib/effects/variations/blur.dart index 8eb5948..c419935 100644 --- a/lib/effects/variations/blur.dart +++ b/lib/effects/variations/blur.dart @@ -4,19 +4,12 @@ import 'package:flutter/widgets.dart'; import '../../flutter_animate.dart'; -//TODO: Impplement this without needing to override begin/end @immutable -class BlurXEffect extends CompositeEffect { - const BlurXEffect({this.begin, this.end, super.delay, super.duration, super.curve}); +class BlurXEffect extends BeginEndEffect with CompositeEffectMixin { + const BlurXEffect({super.begin, super.end, super.delay, super.duration, super.curve}); @override - final double? begin; - - @override - final double? end; - - @override - List get effects => [ + List get effects => [ BlurEffect( begin: Offset(begin ?? BlurEffect.neutralBlur, 0), end: Offset(end ?? (begin == null ? BlurEffect.defaultBlur : BlurEffect.neutralBlur), 0), @@ -37,6 +30,5 @@ extension BlurEffectExtensions on AnimateManager { /// TODO: -/// FadeInDown -/// FadeInLeft -/// FadeInRight \ No newline at end of file +/// BlurY +/// BlurXY diff --git a/lib/effects/variations/fade_in.dart b/lib/effects/variations/fade_in.dart index b44af52..5cde2fa 100644 --- a/lib/effects/variations/fade_in.dart +++ b/lib/effects/variations/fade_in.dart @@ -4,15 +4,15 @@ import 'package:flutter_animate/effects/variations/slide_in.dart'; import '../../flutter_animate.dart'; @immutable -class FadeInEffect extends CompositeEffect { +class FadeInEffect extends Effect with CompositeEffectMixin { const FadeInEffect({super.delay, super.duration, super.curve}); @override - List get effects => const [FadeEffect(begin: 0, end: 1)]; + List get effects => const [FadeEffect(begin: 0, end: 1)]; } @immutable -class FadeInUpEffect extends CompositeEffect { +class FadeInUpEffect extends Effect with CompositeEffectMixin { const FadeInUpEffect({this.beginY, super.delay, super.duration, super.curve}); final double? beginY; diff --git a/lib/effects/variations/fade_out.dart b/lib/effects/variations/fade_out.dart index 5b90699..bb6e4a8 100644 --- a/lib/effects/variations/fade_out.dart +++ b/lib/effects/variations/fade_out.dart @@ -7,7 +7,7 @@ class FadeOutEffect extends CompositeEffect { const FadeOutEffect({super.delay, super.duration, super.curve}); @override - List get effects => const [FadeEffect(begin: 1, end: 0)]; + List get effects => const [FadeEffect(begin: 1, end: 0)]; } @immutable diff --git a/lib/effects/variations/slide_in.dart b/lib/effects/variations/slide_in.dart index 1ce252e..63939d2 100644 --- a/lib/effects/variations/slide_in.dart +++ b/lib/effects/variations/slide_in.dart @@ -9,7 +9,7 @@ class SlideInUpEffect extends CompositeEffect { final double? beginY; @override - List get effects => [ + List get effects => [ SlideEffect(begin: Offset(0, beginY ?? defaultBeginY), end: Offset.zero), ]; } diff --git a/lib/effects/variations/slide_out.dart b/lib/effects/variations/slide_out.dart index f50c574..b773f0c 100644 --- a/lib/effects/variations/slide_out.dart +++ b/lib/effects/variations/slide_out.dart @@ -9,7 +9,7 @@ class SlideOutUpEffect extends CompositeEffect { final double? endY; @override - List get effects => [ + List get effects => [ SlideEffect(begin: Offset.zero, end: Offset(0, endY ?? defaultEndY)), ]; } diff --git a/lib/effects/visibility_effect.dart b/lib/effects/visibility_effect.dart index 4070604..023af1f 100644 --- a/lib/effects/visibility_effect.dart +++ b/lib/effects/visibility_effect.dart @@ -8,7 +8,7 @@ import '../flutter_animate.dart'; /// The `maintain` parameter is assigned to the [Visibility] properties `maintainSize`, /// `maintainAnimation`, `maintainState`, `maintainInteractivity` and `maintainSemantics`. @immutable -class VisibilityEffect extends Effect { +class VisibilityEffect extends BeginEndEffect { static const bool neutralValue = true; static const bool defaultMaintain = true; @@ -29,8 +29,7 @@ class VisibilityEffect extends Effect { final bool maintain; @override - Widget build(BuildContext context, Widget child, - AnimationController controller, EffectEntry entry) { + Widget build(BuildContext context, Widget child, AnimationController controller, EffectEntry entry) { double ratio = getEndRatio(controller, entry); return getToggleBuilder( animation: controller, diff --git a/lib/flutter_animate.dart b/lib/flutter_animate.dart index 97ee505..b5d4b3b 100644 --- a/lib/flutter_animate.dart +++ b/lib/flutter_animate.dart @@ -11,7 +11,7 @@ export 'effects/effects.dart'; export 'extensions/extensions.dart'; -/// Because [Effect] classes are immutable and may be reused between multiple +/// Because [BeginEndEffect] classes are immutable and may be reused between multiple /// [Animate] (or [AnimateList]) instances, an `EffectEntry` is created to store /// values that may be different between instances. For example, due to /// `AnimateList interval`, or from inheriting values from prior effects in the chain. @@ -62,7 +62,7 @@ class EffectEntry { /// runs from 300ms to 800ms with an easeOut curve, within a controller that has a /// total duration of 1000ms. /// -/// Mostly used by [EffectEntry] and [Effect] classes. +/// Mostly used by [EffectEntry] and [BeginEndEffect] classes. Animation buildSubAnimation( AnimationController controller, Duration begin, @@ -77,7 +77,7 @@ Animation buildSubAnimation( ); } -/// Provides a common interface for [Animate] and [AnimateList] to attach [Effect] extensions. +/// Provides a common interface for [Animate] and [AnimateList] to attach [BeginEndEffect] extensions. mixin AnimateManager { T addEffect(Effect effect) => throw (UnimplementedError()); T addEffects(List effects) { From 24a10c9e9781dfc82ca8839ee769776bf7fd113f Mon Sep 17 00:00:00 2001 From: Shawn Date: Wed, 9 Nov 2022 15:10:30 -0700 Subject: [PATCH 05/11] Cleanup --- lib/effects/effect.dart | 20 +++++--------------- lib/effects/variations/blur.dart | 2 +- lib/effects/variations/fade_out.dart | 2 +- lib/effects/variations/slide_in.dart | 2 +- lib/effects/variations/slide_out.dart | 2 +- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/effects/effect.dart b/lib/effects/effect.dart index 72d3847..af4d316 100644 --- a/lib/effects/effect.dart +++ b/lib/effects/effect.dart @@ -2,19 +2,9 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import '../flutter_animate.dart'; -/// An Effect that is composed of or more other existing Effects. Provides -/// syntactic sugar for calling the `composeEffects` method. -abstract class CompositeEffect extends Effect { - const CompositeEffect({super.delay, super.duration, super.curve}); - - @protected - List get effects; - - @override - Widget build(BuildContext context, Widget child, AnimationController controller, EffectEntry entry) => - composeEffects(effects, context, child, controller, entry); -} - +/// Used to easily create effects that are composed of one or more existing Effects. Provides +/// syntactic sugar for overrideing build and calling the `composeEffects` method +/// with a list of effects. mixin CompositeEffectMixin on Effect { List get effects; @@ -51,7 +41,7 @@ class BeginEndEffect extends Effect { /// /// It can be instantiated and added to Animate, but has no visual effect. @immutable -abstract class Effect { +class Effect { const Effect({this.delay, this.duration, this.curve}); /// The specified delay for the effect. If null, will use the delay from the @@ -77,7 +67,7 @@ abstract class Effect { return child; } - /// Calls build on one or more effects, composing them together and returning the resulting widget tree + /// Calls build on one or more effects, composing them together and returning the resulting widget tree. @protected Widget composeEffects( List effects, diff --git a/lib/effects/variations/blur.dart b/lib/effects/variations/blur.dart index c419935..034c2d7 100644 --- a/lib/effects/variations/blur.dart +++ b/lib/effects/variations/blur.dart @@ -9,7 +9,7 @@ class BlurXEffect extends BeginEndEffect with CompositeEffectMixin { const BlurXEffect({super.begin, super.end, super.delay, super.duration, super.curve}); @override - List get effects => [ + List get effects => [ BlurEffect( begin: Offset(begin ?? BlurEffect.neutralBlur, 0), end: Offset(end ?? (begin == null ? BlurEffect.defaultBlur : BlurEffect.neutralBlur), 0), diff --git a/lib/effects/variations/fade_out.dart b/lib/effects/variations/fade_out.dart index bb6e4a8..5b90699 100644 --- a/lib/effects/variations/fade_out.dart +++ b/lib/effects/variations/fade_out.dart @@ -7,7 +7,7 @@ class FadeOutEffect extends CompositeEffect { const FadeOutEffect({super.delay, super.duration, super.curve}); @override - List get effects => const [FadeEffect(begin: 1, end: 0)]; + List get effects => const [FadeEffect(begin: 1, end: 0)]; } @immutable diff --git a/lib/effects/variations/slide_in.dart b/lib/effects/variations/slide_in.dart index 63939d2..1ce252e 100644 --- a/lib/effects/variations/slide_in.dart +++ b/lib/effects/variations/slide_in.dart @@ -9,7 +9,7 @@ class SlideInUpEffect extends CompositeEffect { final double? beginY; @override - List get effects => [ + List get effects => [ SlideEffect(begin: Offset(0, beginY ?? defaultBeginY), end: Offset.zero), ]; } diff --git a/lib/effects/variations/slide_out.dart b/lib/effects/variations/slide_out.dart index b773f0c..f50c574 100644 --- a/lib/effects/variations/slide_out.dart +++ b/lib/effects/variations/slide_out.dart @@ -9,7 +9,7 @@ class SlideOutUpEffect extends CompositeEffect { final double? endY; @override - List get effects => [ + List get effects => [ SlideEffect(begin: Offset.zero, end: Offset(0, endY ?? defaultEndY)), ]; } From 1db5620b1727d8b55f8a6cef7699fc6381db7a01 Mon Sep 17 00:00:00 2001 From: Shawn Date: Wed, 9 Nov 2022 18:31:13 -0700 Subject: [PATCH 06/11] Remove deprecated CompositeEffect class, replaced with Mixin --- lib/effects/variations/blur.dart | 10 +++++----- lib/effects/variations/fade_in.dart | 14 ++++++++------ lib/effects/variations/fade_out.dart | 23 ++++++++++------------- lib/effects/variations/slide_in.dart | 16 ++++++++-------- lib/effects/variations/slide_out.dart | 15 +++++++-------- 5 files changed, 38 insertions(+), 40 deletions(-) diff --git a/lib/effects/variations/blur.dart b/lib/effects/variations/blur.dart index 034c2d7..9df0a50 100644 --- a/lib/effects/variations/blur.dart +++ b/lib/effects/variations/blur.dart @@ -4,6 +4,11 @@ import 'package:flutter/widgets.dart'; import '../../flutter_animate.dart'; +/* +TODO: + BlurY + BlurXY +*/ @immutable class BlurXEffect extends BeginEndEffect with CompositeEffectMixin { const BlurXEffect({super.begin, super.end, super.delay, super.duration, super.curve}); @@ -27,8 +32,3 @@ extension BlurEffectExtensions on AnimateManager { }) => addEffect(BlurXEffect(delay: delay, duration: duration, curve: curve)); } - - -/// TODO: -/// BlurY -/// BlurXY diff --git a/lib/effects/variations/fade_in.dart b/lib/effects/variations/fade_in.dart index 5cde2fa..7b71ac5 100644 --- a/lib/effects/variations/fade_in.dart +++ b/lib/effects/variations/fade_in.dart @@ -3,12 +3,19 @@ import 'package:flutter_animate/effects/variations/slide_in.dart'; import '../../flutter_animate.dart'; +/* +TODO: + FadeInDown + FadeInLeft + FadeInRight +*/ + @immutable class FadeInEffect extends Effect with CompositeEffectMixin { const FadeInEffect({super.delay, super.duration, super.curve}); @override - List get effects => const [FadeEffect(begin: 0, end: 1)]; + List get effects => const [FadeEffect(begin: 0, end: 1)]; } @immutable @@ -24,11 +31,6 @@ class FadeInUpEffect extends Effect with CompositeEffectMixin { ]; } -/// TODO: -/// FadeInDown -/// FadeInLeft -/// FadeInRight - extension FadeInEffectExtensions on AnimateManager { T fadeIn({Duration? delay, Duration? duration, Curve? curve}) => addEffect(FadeInEffect(delay: delay, duration: duration, curve: curve)); diff --git a/lib/effects/variations/fade_out.dart b/lib/effects/variations/fade_out.dart index 5b90699..2ddd4ba 100644 --- a/lib/effects/variations/fade_out.dart +++ b/lib/effects/variations/fade_out.dart @@ -2,8 +2,15 @@ import 'package:flutter/widgets.dart'; import '../../flutter_animate.dart'; +/* +TODO: +FadeOutDown +FadeOutLeft +FadeOutRight +*/ + @immutable -class FadeOutEffect extends CompositeEffect { +class FadeOutEffect extends Effect with CompositeEffectMixin { const FadeOutEffect({super.delay, super.duration, super.curve}); @override @@ -11,25 +18,15 @@ class FadeOutEffect extends CompositeEffect { } @immutable -class FadeOutUpEffect extends CompositeEffect { +class FadeOutUpEffect extends Effect with CompositeEffectMixin { const FadeOutUpEffect({this.endY, super.delay, super.duration, super.curve}); final double? endY; @override - List get effects => [ - const FadeOutEffect(), - SlideOutUpEffect(endY: endY), - ]; + List get effects => [const FadeOutEffect(), SlideOutUpEffect(endY: endY)]; } -/* -TODO: -FadeOutDown -FadeOutLeft -FadeOutRight -*/ - extension FadeOutEffectExtensions on AnimateManager { T fadeOut({Duration? delay, Duration? duration, Curve? curve}) => addEffect(FadeOutEffect(delay: delay, duration: duration, curve: curve)); diff --git a/lib/effects/variations/slide_in.dart b/lib/effects/variations/slide_in.dart index 1ce252e..a92ad47 100644 --- a/lib/effects/variations/slide_in.dart +++ b/lib/effects/variations/slide_in.dart @@ -2,8 +2,15 @@ import 'package:flutter/widgets.dart'; import '../../flutter_animate.dart'; +/* +TODO: +SlideInDown +SlideInLeft +SlideInRight +*/ + @immutable -class SlideInUpEffect extends CompositeEffect { +class SlideInUpEffect extends Effect with CompositeEffectMixin { const SlideInUpEffect({this.beginY, super.delay, super.duration, super.curve}); static const defaultBeginY = -.2; final double? beginY; @@ -14,13 +21,6 @@ class SlideInUpEffect extends CompositeEffect { ]; } -/* -TODO: -SlideInDown -SlideInLeft -SlideInRight -*/ - extension SlideInExtensions on AnimateManager { T slideInUp({double? beginY, Duration? delay, Duration? duration, Curve? curve}) => addEffect(SlideInUpEffect(beginY: beginY, delay: delay, duration: duration, curve: curve)); diff --git a/lib/effects/variations/slide_out.dart b/lib/effects/variations/slide_out.dart index f50c574..8ba5a08 100644 --- a/lib/effects/variations/slide_out.dart +++ b/lib/effects/variations/slide_out.dart @@ -2,8 +2,14 @@ import 'package:flutter/widgets.dart'; import '../../flutter_animate.dart'; +/* +TODO: +SlideOutDown +SlideOutLeft +SlideOutRight +*/ @immutable -class SlideOutUpEffect extends CompositeEffect { +class SlideOutUpEffect extends Effect with CompositeEffectMixin { const SlideOutUpEffect({this.endY, super.delay, super.duration, super.curve}); static const defaultEndY = .2; final double? endY; @@ -14,13 +20,6 @@ class SlideOutUpEffect extends CompositeEffect { ]; } -/* -TODO: -SlideOutDown -SlideOutLeft -SlideOutRight -*/ - extension SlideOutExtensions on AnimateManager { T slideOutUp({double? endY, Duration? delay, Duration? duration, Curve? curve}) => addEffect(SlideOutUpEffect(endY: endY, delay: delay, duration: duration, curve: curve)); From eaf8ab8311ba78bd25b54ef6a644a08d4e2b0c03 Mon Sep 17 00:00:00 2001 From: Shawn Date: Wed, 9 Nov 2022 18:45:36 -0700 Subject: [PATCH 07/11] More cleanup --- lib/animate.dart | 6 +++--- lib/animate_list.dart | 6 +++--- lib/effects/variations/fade_in.dart | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/animate.dart b/lib/animate.dart index ba1abf7..78247db 100644 --- a/lib/animate.dart +++ b/lib/animate.dart @@ -134,7 +134,7 @@ class Animate extends StatefulWidget with AnimateManager { /// ``` final AnimateCallback? onPlay; - /// Defines a delay before the animation is started. Unlike [BeginEndEffect.delay], + /// Defines a delay before the animation is started. Unlike [Effect.delay], /// this is not a part of the overall animation, and only runs once if the /// animation is looped. [onPlay] is called after this delay. final Duration delay; @@ -163,7 +163,7 @@ class Animate extends StatefulWidget with AnimateManager { @override State createState() => _AnimateState(); - /// Adds an effect. This is mostly used by [BeginEndEffect] extension methods to append effects + /// Adds an effect. This is mostly used by [Effect] extension methods to append effects /// to an [Animate] instance. @override Animate addEffect(Effect effect) { @@ -284,7 +284,7 @@ class _AnimateState extends State with SingleTickerProviderStateMixin { extension AnimateWidgetExtensions on Widget { Animate animate({ Key? key, - List? effects, + List? effects, AnimateCallback? onComplete, AnimateCallback? onPlay, Duration delay = Duration.zero, diff --git a/lib/animate_list.dart b/lib/animate_list.dart index 392c109..c450dbc 100644 --- a/lib/animate_list.dart +++ b/lib/animate_list.dart @@ -46,7 +46,7 @@ class AnimateList extends ListBase with AnimateManager /// instance, and proxy any added effects to each of them. AnimateList({ required List children, - List? effects, + List? effects, Duration? interval, AnimateCallback? onPlay, AnimateCallback? onComplete, @@ -75,7 +75,7 @@ class AnimateList extends ListBase with AnimateManager final List _widgets = []; final List _managers = []; - /// Adds an effect. This is mostly used by [BeginEndEffect] extension methods to + /// Adds an effect. This is mostly used by [Effect] extension methods to /// append effects to an [AnimateList] instance. @override AnimateList addEffect(Effect effect) { @@ -107,7 +107,7 @@ class AnimateList extends ListBase with AnimateManager /// Ex. `[foo, bar].animate()` is equivalent to `AnimateList(children: [foo, bar])`. extension AnimateListExtensions on List { AnimateList animate({ - List? effects, + List? effects, Duration? interval, AnimateCallback? onPlay, AnimateCallback? onComplete, diff --git a/lib/effects/variations/fade_in.dart b/lib/effects/variations/fade_in.dart index 7b71ac5..bcc031e 100644 --- a/lib/effects/variations/fade_in.dart +++ b/lib/effects/variations/fade_in.dart @@ -1,5 +1,4 @@ import 'package:flutter/widgets.dart'; -import 'package:flutter_animate/effects/variations/slide_in.dart'; import '../../flutter_animate.dart'; From 3612a583d04d8086a046c4568d8724ebc540dceb Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 10 Nov 2022 10:25:24 -0700 Subject: [PATCH 08/11] Add dedicated effect_entry class for better organization --- lib/effect_entry.dart | 63 ++++++++++++++++++++++++++++++++++++++++ lib/flutter_animate.dart | 50 ++----------------------------- 2 files changed, 65 insertions(+), 48 deletions(-) create mode 100644 lib/effect_entry.dart diff --git a/lib/effect_entry.dart b/lib/effect_entry.dart new file mode 100644 index 0000000..c50d4f6 --- /dev/null +++ b/lib/effect_entry.dart @@ -0,0 +1,63 @@ +import 'package:flutter/widgets.dart'; +import 'package:flutter_animate/flutter_animate.dart'; + +import 'effects/effects.dart'; +import 'animate.dart'; +import 'animate_list.dart'; + +export 'animate.dart'; +export 'animate_list.dart'; +export 'adapters/adapters.dart'; +export 'effects/effects.dart'; + +export 'extensions/extensions.dart'; + +/// Because [Effect] classes are immutable and may be reused between multiple +/// [Animate] (or [AnimateList]) instances, an `EffectEntry` is created to store +/// values that may be different between instances. For example, due to +/// `AnimateList interval`, or from inheriting values from prior effects in the chain. +@immutable +class EffectEntry { + const EffectEntry({ + required this.effect, + required this.delay, + required this.duration, + required this.curve, + required this.owner, + }); + + /// The delay for this entry. + final Duration delay; + + /// The duration for this entry. + final Duration duration; + + /// The curve used by this entry. + final Curve curve; + + /// The effect associated with this entry. + final Effect effect; + + /// The [Animate] instance that created this entry. This can be used by effects + /// to read information about the animation. Effects _should not_ modify + /// the animation (ex. by calling [Animate.addEffect]). + final Animate owner; + + /// The begin time for this entry. + Duration get begin => delay; + + /// The end time for this entry. + Duration get end => delay + duration; + + /// Builds a sub-animation that runs from 0-1, based on the properties of this entry. + Animation buildAnimation( + AnimationController controller, { + Curve? curve, + }) { + return buildSubAnimation(controller, begin, end, curve ?? this.curve); + } + + /// Builds an sub-animation that runs from the begin and end values of a given [Tween] + Animation buildTweenedAnimation(AnimationController controller, Tween tween) => + buildAnimation(controller).drive(tween); +} diff --git a/lib/flutter_animate.dart b/lib/flutter_animate.dart index b5d4b3b..a2f4c96 100644 --- a/lib/flutter_animate.dart +++ b/lib/flutter_animate.dart @@ -8,61 +8,15 @@ export 'animate.dart'; export 'animate_list.dart'; export 'adapters/adapters.dart'; export 'effects/effects.dart'; - +export 'effect_entry.dart'; export 'extensions/extensions.dart'; -/// Because [BeginEndEffect] classes are immutable and may be reused between multiple -/// [Animate] (or [AnimateList]) instances, an `EffectEntry` is created to store -/// values that may be different between instances. For example, due to -/// `AnimateList interval`, or from inheriting values from prior effects in the chain. -@immutable -class EffectEntry { - const EffectEntry({ - required this.effect, - required this.delay, - required this.duration, - required this.curve, - required this.owner, - }); - - /// The delay for this entry. - final Duration delay; - - /// The duration for this entry. - final Duration duration; - - /// The curve used by this entry. - final Curve curve; - - /// The effect associated with this entry. - final Effect effect; - - /// The [Animate] instance that created this entry. This can be used by effects - /// to read information about the animation. Effects _should not_ modify - /// the animation (ex. by calling [Animate.addEffect]). - final Animate owner; - - /// The begin time for this entry. - Duration get begin => delay; - - /// The end time for this entry. - Duration get end => delay + duration; - - /// Builds a sub-animation based on the properties of this entry. - Animation buildAnimation( - AnimationController controller, { - Curve? curve, - }) { - return buildSubAnimation(controller, begin, end, curve ?? this.curve); - } -} - /// Builds a sub-animation to the provided controller that runs from start to /// end, with the provided curve. For example, it could create an animation that /// runs from 300ms to 800ms with an easeOut curve, within a controller that has a /// total duration of 1000ms. /// -/// Mostly used by [EffectEntry] and [BeginEndEffect] classes. +/// Mostly used by [EffectEntry] and [Effect] classes. Animation buildSubAnimation( AnimationController controller, Duration begin, From 45ef6b2987c93c58cd2187873eb6a1f2f181b7d5 Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 10 Nov 2022 10:27:10 -0700 Subject: [PATCH 09/11] Refactor to simplify inheritence chain. Renamed `buildAnimation` to `buildBeginEndAnimation` to make things a little more clear. --- lib/effect_entry.dart | 4 ---- lib/effects/blur_effect.dart | 2 +- lib/effects/custom_effect.dart | 2 +- lib/effects/effect.dart | 12 ++++-------- lib/effects/fade_effect.dart | 2 +- lib/effects/move_effect.dart | 2 +- lib/effects/rotate_effect.dart | 2 +- lib/effects/saturate_effect.dart | 2 +- lib/effects/scale_effect.dart | 2 +- lib/effects/shake_effect.dart | 2 +- lib/effects/shimmer_effect.dart | 2 +- lib/effects/slide_effect.dart | 2 +- lib/effects/tint_effect.dart | 2 +- 13 files changed, 15 insertions(+), 23 deletions(-) diff --git a/lib/effect_entry.dart b/lib/effect_entry.dart index c50d4f6..f4f321c 100644 --- a/lib/effect_entry.dart +++ b/lib/effect_entry.dart @@ -1,10 +1,6 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_animate/flutter_animate.dart'; -import 'effects/effects.dart'; -import 'animate.dart'; -import 'animate_list.dart'; - export 'animate.dart'; export 'animate_list.dart'; export 'adapters/adapters.dart'; diff --git a/lib/effects/blur_effect.dart b/lib/effects/blur_effect.dart index 34deada..29d08ba 100644 --- a/lib/effects/blur_effect.dart +++ b/lib/effects/blur_effect.dart @@ -35,7 +35,7 @@ class BlurEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildAnimation(controller, entry); + Animation animation = buildBeginEndAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/custom_effect.dart b/lib/effects/custom_effect.dart index 315dbc7..768306c 100644 --- a/lib/effects/custom_effect.dart +++ b/lib/effects/custom_effect.dart @@ -38,7 +38,7 @@ class CustomEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildAnimation(controller, entry); + Animation animation = buildTweenedAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (ctx, __) => builder(ctx, animation.value, child), diff --git a/lib/effects/effect.dart b/lib/effects/effect.dart index af4d316..8c86858 100644 --- a/lib/effects/effect.dart +++ b/lib/effects/effect.dart @@ -25,13 +25,9 @@ class BeginEndEffect extends Effect { /// default value when appropriate. final T? end; - /// Returns an animation based on the controller, entry, and begin/end values. - Animation buildAnimation( - AnimationController controller, - EffectEntry entry, - ) { - return entry.buildAnimation(controller).drive(Tween(begin: begin, end: end)); - } + /// Helper method for concrete effects to easily create an Animation from the current begin/end values. + Animation buildBeginEndAnimation(AnimationController controller, EffectEntry entry) => + entry.buildTweenedAnimation(controller, Tween(begin: begin, end: end)); } /// Class that defines the required interface and helper methods for @@ -41,7 +37,7 @@ class BeginEndEffect extends Effect { /// /// It can be instantiated and added to Animate, but has no visual effect. @immutable -class Effect { +class Effect { const Effect({this.delay, this.duration, this.curve}); /// The specified delay for the effect. If null, will use the delay from the diff --git a/lib/effects/fade_effect.dart b/lib/effects/fade_effect.dart index 78f72a4..e8b8853 100644 --- a/lib/effects/fade_effect.dart +++ b/lib/effects/fade_effect.dart @@ -31,7 +31,7 @@ class FadeEffect extends BeginEndEffect { EffectEntry entry, ) { return FadeTransition( - opacity: buildAnimation(controller, entry), + opacity: buildBeginEndAnimation(controller, entry), child: child, ); } diff --git a/lib/effects/move_effect.dart b/lib/effects/move_effect.dart index bf010a2..ffead0d 100644 --- a/lib/effects/move_effect.dart +++ b/lib/effects/move_effect.dart @@ -41,7 +41,7 @@ class MoveEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildAnimation(controller, entry); + Animation animation = buildTweenedAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/rotate_effect.dart b/lib/effects/rotate_effect.dart index 535eb16..81503f6 100644 --- a/lib/effects/rotate_effect.dart +++ b/lib/effects/rotate_effect.dart @@ -38,7 +38,7 @@ class RotateEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildAnimation(controller, entry); + Animation animation = buildTweenedAnimation(controller, entry); return RotationTransition( turns: animation, alignment: alignment ?? Alignment.center, diff --git a/lib/effects/saturate_effect.dart b/lib/effects/saturate_effect.dart index d369055..e58c4b4 100644 --- a/lib/effects/saturate_effect.dart +++ b/lib/effects/saturate_effect.dart @@ -38,7 +38,7 @@ class SaturateEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildAnimation(controller, entry); + Animation animation = buildTweenedAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/scale_effect.dart b/lib/effects/scale_effect.dart index 263406a..6571460 100644 --- a/lib/effects/scale_effect.dart +++ b/lib/effects/scale_effect.dart @@ -36,7 +36,7 @@ class ScaleEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildAnimation(controller, entry); + Animation animation = buildTweenedAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/shake_effect.dart b/lib/effects/shake_effect.dart index 2add2d3..611a1f8 100644 --- a/lib/effects/shake_effect.dart +++ b/lib/effects/shake_effect.dart @@ -60,7 +60,7 @@ class ShakeEffect extends BeginEndEffect { final bool shouldTranslate = offset != Offset.zero; if (!shouldRotate && !shouldTranslate) return child; - final Animation animation = buildAnimation(controller, entry); + final Animation animation = buildTweenedAnimation(controller, entry); final int count = (entry.duration.inMilliseconds / 1000 * hz).round(); return getOptimizedBuilder( diff --git a/lib/effects/shimmer_effect.dart b/lib/effects/shimmer_effect.dart index dab89e9..ae42104 100644 --- a/lib/effects/shimmer_effect.dart +++ b/lib/effects/shimmer_effect.dart @@ -60,7 +60,7 @@ class ShimmerEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildAnimation(controller, entry); + Animation animation = buildTweenedAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/slide_effect.dart b/lib/effects/slide_effect.dart index cccdd88..0b2547f 100644 --- a/lib/effects/slide_effect.dart +++ b/lib/effects/slide_effect.dart @@ -37,7 +37,7 @@ class SlideEffect extends BeginEndEffect { EffectEntry entry, ) { return SlideTransition( - position: buildAnimation(controller, entry), + position: buildTweenedAnimation(controller, entry), child: child, ); } diff --git a/lib/effects/tint_effect.dart b/lib/effects/tint_effect.dart index 4e9fb7b..3d03818 100644 --- a/lib/effects/tint_effect.dart +++ b/lib/effects/tint_effect.dart @@ -44,7 +44,7 @@ class TintEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildAnimation(controller, entry); + Animation animation = buildBeginEndAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { From fe44db72f9848ef4d910c52ebef9f470eaefd7df Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 10 Nov 2022 10:31:41 -0700 Subject: [PATCH 10/11] Moved effect into the root folder for better visibility --- lib/{effects => }/effect.dart | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/{effects => }/effect.dart (100%) diff --git a/lib/effects/effect.dart b/lib/effect.dart similarity index 100% rename from lib/effects/effect.dart rename to lib/effect.dart From c7aa1a151f460d6d8238a94e9e7193fb3955187f Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 10 Nov 2022 10:55:53 -0700 Subject: [PATCH 11/11] Change Then, Toggle, Callback and Swap to extend Effect directly since they have no use for begin/end --- lib/effect.dart | 2 +- lib/effects/callback_effect.dart | 2 +- lib/effects/custom_effect.dart | 2 +- lib/effects/effects.dart | 2 -- lib/effects/flip_effect.dart | 2 +- lib/effects/move_effect.dart | 2 +- lib/effects/rotate_effect.dart | 2 +- lib/effects/saturate_effect.dart | 2 +- lib/effects/scale_effect.dart | 2 +- lib/effects/shake_effect.dart | 2 +- lib/effects/shimmer_effect.dart | 2 +- lib/effects/slide_effect.dart | 2 +- lib/effects/swap_effect.dart | 2 +- lib/effects/then_effect.dart | 2 +- lib/effects/toggle_effect.dart | 2 +- lib/flutter_animate.dart | 6 +++--- 16 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/effect.dart b/lib/effect.dart index 8c86858..23e7fce 100644 --- a/lib/effect.dart +++ b/lib/effect.dart @@ -1,6 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; -import '../flutter_animate.dart'; +import 'flutter_animate.dart'; /// Used to easily create effects that are composed of one or more existing Effects. Provides /// syntactic sugar for overrideing build and calling the `composeEffects` method diff --git a/lib/effects/callback_effect.dart b/lib/effects/callback_effect.dart index b481a28..bde4b58 100644 --- a/lib/effects/callback_effect.dart +++ b/lib/effects/callback_effect.dart @@ -27,7 +27,7 @@ import '../flutter_animate.dart'; /// an animation that is driven by an [Adapter] (or manipulated via its controller) /// may behave unexpectedly in certain circumstances. @immutable -class CallbackEffect extends BeginEndEffect { +class CallbackEffect extends Effect { const CallbackEffect({ Duration? delay, Duration? duration, diff --git a/lib/effects/custom_effect.dart b/lib/effects/custom_effect.dart index 768306c..afe4db4 100644 --- a/lib/effects/custom_effect.dart +++ b/lib/effects/custom_effect.dart @@ -38,7 +38,7 @@ class CustomEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildTweenedAnimation(controller, entry); + Animation animation = buildBeginEndAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (ctx, __) => builder(ctx, animation.value, child), diff --git a/lib/effects/effects.dart b/lib/effects/effects.dart index 4217685..11b9464 100644 --- a/lib/effects/effects.dart +++ b/lib/effects/effects.dart @@ -1,6 +1,4 @@ // collects effect classes for easy import. -export 'effect.dart'; - export 'blur_effect.dart'; export 'callback_effect.dart'; export 'custom_effect.dart'; diff --git a/lib/effects/flip_effect.dart b/lib/effects/flip_effect.dart index 878aea9..1dd6058 100644 --- a/lib/effects/flip_effect.dart +++ b/lib/effects/flip_effect.dart @@ -60,7 +60,7 @@ class FlipEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildAnimation(controller, entry); + Animation animation = buildBeginEndAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/move_effect.dart b/lib/effects/move_effect.dart index ffead0d..2c6a3fd 100644 --- a/lib/effects/move_effect.dart +++ b/lib/effects/move_effect.dart @@ -41,7 +41,7 @@ class MoveEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildTweenedAnimation(controller, entry); + Animation animation = buildBeginEndAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/rotate_effect.dart b/lib/effects/rotate_effect.dart index 81503f6..b79ec04 100644 --- a/lib/effects/rotate_effect.dart +++ b/lib/effects/rotate_effect.dart @@ -38,7 +38,7 @@ class RotateEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildTweenedAnimation(controller, entry); + Animation animation = buildBeginEndAnimation(controller, entry); return RotationTransition( turns: animation, alignment: alignment ?? Alignment.center, diff --git a/lib/effects/saturate_effect.dart b/lib/effects/saturate_effect.dart index e58c4b4..a7fdc11 100644 --- a/lib/effects/saturate_effect.dart +++ b/lib/effects/saturate_effect.dart @@ -38,7 +38,7 @@ class SaturateEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildTweenedAnimation(controller, entry); + Animation animation = buildBeginEndAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/scale_effect.dart b/lib/effects/scale_effect.dart index 6571460..59d9381 100644 --- a/lib/effects/scale_effect.dart +++ b/lib/effects/scale_effect.dart @@ -36,7 +36,7 @@ class ScaleEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildTweenedAnimation(controller, entry); + Animation animation = buildBeginEndAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/shake_effect.dart b/lib/effects/shake_effect.dart index 611a1f8..e96670d 100644 --- a/lib/effects/shake_effect.dart +++ b/lib/effects/shake_effect.dart @@ -60,7 +60,7 @@ class ShakeEffect extends BeginEndEffect { final bool shouldTranslate = offset != Offset.zero; if (!shouldRotate && !shouldTranslate) return child; - final Animation animation = buildTweenedAnimation(controller, entry); + final Animation animation = buildBeginEndAnimation(controller, entry); final int count = (entry.duration.inMilliseconds / 1000 * hz).round(); return getOptimizedBuilder( diff --git a/lib/effects/shimmer_effect.dart b/lib/effects/shimmer_effect.dart index ae42104..26bc043 100644 --- a/lib/effects/shimmer_effect.dart +++ b/lib/effects/shimmer_effect.dart @@ -60,7 +60,7 @@ class ShimmerEffect extends BeginEndEffect { AnimationController controller, EffectEntry entry, ) { - Animation animation = buildTweenedAnimation(controller, entry); + Animation animation = buildBeginEndAnimation(controller, entry); return getOptimizedBuilder( animation: animation, builder: (_, __) { diff --git a/lib/effects/slide_effect.dart b/lib/effects/slide_effect.dart index 0b2547f..72155b4 100644 --- a/lib/effects/slide_effect.dart +++ b/lib/effects/slide_effect.dart @@ -37,7 +37,7 @@ class SlideEffect extends BeginEndEffect { EffectEntry entry, ) { return SlideTransition( - position: buildTweenedAnimation(controller, entry), + position: buildBeginEndAnimation(controller, entry), child: child, ); } diff --git a/lib/effects/swap_effect.dart b/lib/effects/swap_effect.dart index 8930ec0..4736878 100644 --- a/lib/effects/swap_effect.dart +++ b/lib/effects/swap_effect.dart @@ -36,7 +36,7 @@ import '../flutter_animate.dart'; /// [AnimationController]. So, for example, repeating the first animation (the /// fade out) via its controller will not affect the second animation (fade in). @immutable -class SwapEffect extends BeginEndEffect { +class SwapEffect extends Effect { const SwapEffect({ Duration? delay, Duration? duration, diff --git a/lib/effects/then_effect.dart b/lib/effects/then_effect.dart index 9f35cfe..d9c1433 100644 --- a/lib/effects/then_effect.dart +++ b/lib/effects/then_effect.dart @@ -28,7 +28,7 @@ import '../flutter_animate.dart'; /// subsequent effect. In the example above, it is functionally equivalent to /// setting `delay: 1400.ms` on the blur effect. @immutable -class ThenEffect extends BeginEndEffect { +class ThenEffect extends Effect { // NOTE: this is just an empty effect, the logic happens in Animate // when it recognizes the type. const ThenEffect({Duration? delay, Duration? duration, Curve? curve}) diff --git a/lib/effects/toggle_effect.dart b/lib/effects/toggle_effect.dart index 15e46ca..c305537 100644 --- a/lib/effects/toggle_effect.dart +++ b/lib/effects/toggle_effect.dart @@ -20,7 +20,7 @@ import '../flutter_animate.dart'; /// The child of `Animate` is passed through to the builder in the `child` param /// (possibly already wrapped by prior effects). @immutable -class ToggleEffect extends BeginEndEffect { +class ToggleEffect extends Effect { const ToggleEffect({ Duration? delay, Duration? duration, diff --git a/lib/flutter_animate.dart b/lib/flutter_animate.dart index a2f4c96..de6ee44 100644 --- a/lib/flutter_animate.dart +++ b/lib/flutter_animate.dart @@ -1,14 +1,14 @@ import 'package:flutter/widgets.dart'; -import 'effects/effects.dart'; -import 'animate.dart'; -import 'animate_list.dart'; +import 'effect.dart'; export 'animate.dart'; export 'animate_list.dart'; export 'adapters/adapters.dart'; export 'effects/effects.dart'; export 'effect_entry.dart'; +export 'effect.dart'; +export 'effects/effects.dart'; export 'extensions/extensions.dart'; /// Builds a sub-animation to the provided controller that runs from start to