From 94ed6d17adc6ae2474fc077569fb6b464c4f174b Mon Sep 17 00:00:00 2001 From: fauziridwan1709 Date: Sun, 10 Sep 2023 16:49:41 +0700 Subject: [PATCH 1/4] feat: add SlideDirection enum and logic for slide-in-out tween --- lib/src/rotate.dart | 89 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 8 deletions(-) diff --git a/lib/src/rotate.dart b/lib/src/rotate.dart index c573c80..376eef7 100644 --- a/lib/src/rotate.dart +++ b/lib/src/rotate.dart @@ -1,6 +1,15 @@ import 'package:flutter/material.dart'; + import 'animated_text.dart'; +/// Enum to control the slide direction. +enum SlideDirection { + leftToRight, + rightToLeft, + topToBottom, + bottomToTop, +} + /// Animated Text that rotates a [Text] in and then out. /// /// ![Rotate example](https://raw.githubusercontent.com/aagarwal1012/Animated-Text-Kit/master/display/rotate.gif) @@ -30,6 +39,11 @@ class RotateAnimatedText extends AnimatedText { /// By default, it is set to true. final bool rotateOut; + /// Control slide animation direction. + /// + /// By default. it is set to [SlideDirection.topToBottom] + final SlideDirection slideDirection; + RotateAnimatedText( String text, { TextAlign textAlign = TextAlign.start, @@ -39,6 +53,7 @@ class RotateAnimatedText extends AnimatedText { this.alignment = Alignment.center, this.textDirection = TextDirection.ltr, this.rotateOut = true, + this.slideDirection = SlideDirection.bottomToTop, }) : super( text: text, textAlign: textAlign, @@ -55,10 +70,35 @@ class RotateAnimatedText extends AnimatedText { final inIntervalEnd = rotateOut ? 0.4 : 1.0; - _slideIn = AlignmentTween( - begin: Alignment.topCenter.add(alignment).resolve(direction), - end: Alignment.center.add(alignment).resolve(direction), - ).animate( + AlignmentTween slideInTween; + switch (slideDirection) { + case SlideDirection.leftToRight: + slideInTween = AlignmentTween( + begin: Alignment.centerLeft.add(alignment).resolve(direction), + end: Alignment.center.add(alignment).resolve(direction), + ); + break; + case SlideDirection.rightToLeft: + slideInTween = AlignmentTween( + begin: Alignment.centerRight.add(alignment).resolve(direction), + end: Alignment.center.add(alignment).resolve(direction), + ); + break; + case SlideDirection.topToBottom: + slideInTween = AlignmentTween( + begin: Alignment.topCenter.add(alignment).resolve(direction), + end: Alignment.center.add(alignment).resolve(direction), + ); + break; + case SlideDirection.bottomToTop: + slideInTween = AlignmentTween( + begin: Alignment.bottomCenter.add(alignment).resolve(direction), + end: Alignment.center.add(alignment).resolve(direction), + ); + break; + } + + _slideIn = slideInTween.animate( CurvedAnimation( parent: controller, curve: Interval(0.0, inIntervalEnd, curve: Curves.linear), @@ -73,10 +113,35 @@ class RotateAnimatedText extends AnimatedText { ); if (rotateOut) { - _slideOut = AlignmentTween( - begin: Alignment.center.add(alignment).resolve(direction), - end: Alignment.bottomCenter.add(alignment).resolve(direction), - ).animate( + AlignmentTween slideOutTween; + switch (slideDirection) { + case SlideDirection.leftToRight: + slideOutTween = AlignmentTween( + begin: Alignment.center.add(alignment).resolve(direction), + end: Alignment.centerRight.add(alignment).resolve(direction), + ); + break; + case SlideDirection.rightToLeft: + slideOutTween = AlignmentTween( + begin: Alignment.center.add(alignment).resolve(direction), + end: Alignment.centerLeft.add(alignment).resolve(direction), + ); + break; + case SlideDirection.topToBottom: + slideOutTween = AlignmentTween( + begin: Alignment.center.add(alignment).resolve(direction), + end: Alignment.bottomCenter.add(alignment).resolve(direction), + ); + break; + case SlideDirection.bottomToTop: + slideOutTween = AlignmentTween( + begin: Alignment.center.add(alignment).resolve(direction), + end: Alignment.topCenter.add(alignment).resolve(direction), + ); + break; + } + + _slideOut = slideOutTween.animate( CurvedAnimation( parent: controller, curve: const Interval(0.7, 1.0, curve: Curves.linear), @@ -184,3 +249,11 @@ class RotateAnimatedTextKit extends AnimatedTextKit { )) .toList(); } + +// Hi, I'm Yashas this will be my first contribution. +// +// I had a pretty cool idea when I was working on a todo app, I wanted to mark the task as done and strikethrough the text but there was no option to do so with an animation. I looked through various libraries but wasn't able to find a good one. +// +// I have been using animated text kit for some time a now and thought of contributing to the library by adding a strike through animation. +// +// Is anyone working on this? If not, may I contribute to this? From d01e25688d8e6993db23e429c1bce43fffd038c5 Mon Sep 17 00:00:00 2001 From: fauziridwan1709 Date: Sun, 10 Sep 2023 16:50:40 +0700 Subject: [PATCH 2/4] feat: update default value for slideDirection --- lib/src/rotate.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/rotate.dart b/lib/src/rotate.dart index 376eef7..0cfdf25 100644 --- a/lib/src/rotate.dart +++ b/lib/src/rotate.dart @@ -53,7 +53,7 @@ class RotateAnimatedText extends AnimatedText { this.alignment = Alignment.center, this.textDirection = TextDirection.ltr, this.rotateOut = true, - this.slideDirection = SlideDirection.bottomToTop, + this.slideDirection = SlideDirection.topToBottom, }) : super( text: text, textAlign: textAlign, From a0da40a15aab69d1f6e38e41bab1f79e7c43365a Mon Sep 17 00:00:00 2001 From: fauziridwan1709 Date: Sun, 10 Sep 2023 16:51:28 +0700 Subject: [PATCH 3/4] feat: make both slideInTween and slideOutTween as late final variables --- lib/src/rotate.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/rotate.dart b/lib/src/rotate.dart index 0cfdf25..186d859 100644 --- a/lib/src/rotate.dart +++ b/lib/src/rotate.dart @@ -70,7 +70,7 @@ class RotateAnimatedText extends AnimatedText { final inIntervalEnd = rotateOut ? 0.4 : 1.0; - AlignmentTween slideInTween; + late final AlignmentTween slideInTween; switch (slideDirection) { case SlideDirection.leftToRight: slideInTween = AlignmentTween( @@ -113,7 +113,7 @@ class RotateAnimatedText extends AnimatedText { ); if (rotateOut) { - AlignmentTween slideOutTween; + late final AlignmentTween slideOutTween; switch (slideDirection) { case SlideDirection.leftToRight: slideOutTween = AlignmentTween( From 5f7afbe9e9aeb53f6522edc785667b940cf78b73 Mon Sep 17 00:00:00 2001 From: fauziridwan1709 Date: Sun, 10 Sep 2023 17:07:01 +0700 Subject: [PATCH 4/4] feat: remove unrelated comments --- lib/src/rotate.dart | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/src/rotate.dart b/lib/src/rotate.dart index 186d859..f673e8c 100644 --- a/lib/src/rotate.dart +++ b/lib/src/rotate.dart @@ -249,11 +249,3 @@ class RotateAnimatedTextKit extends AnimatedTextKit { )) .toList(); } - -// Hi, I'm Yashas this will be my first contribution. -// -// I had a pretty cool idea when I was working on a todo app, I wanted to mark the task as done and strikethrough the text but there was no option to do so with an animation. I looked through various libraries but wasn't able to find a good one. -// -// I have been using animated text kit for some time a now and thought of contributing to the library by adding a strike through animation. -// -// Is anyone working on this? If not, may I contribute to this?