diff --git a/README.md b/README.md index e71a4fb..7550eb2 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ AnimatedTextKit( speed: const Duration(milliseconds: 2000), ), ], - + totalRepeatCount: 4, pause: const Duration(milliseconds: 1000), displayFullTextOnTap: true, @@ -409,6 +409,9 @@ return SizedBox( fontWeight: FontWeight.bold, ), boxHeight: 300.0, + onFinished: () { + print("Animation finished!"); + }, ), ); ``` diff --git a/example/lib/main.dart b/example/lib/main.dart index c5c618b..277b9c5 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -287,6 +287,9 @@ List animatedTextExamples({VoidCallback? onTap}) => fontWeight: FontWeight.bold, ), boxHeight: 300, + onFinished: () { + //This is called at the animation end + }, ), ), AnimatedTextExample( diff --git a/lib/src/text_liquid_fill.dart b/lib/src/text_liquid_fill.dart index ca202b4..7bd02dd 100644 --- a/lib/src/text_liquid_fill.dart +++ b/lib/src/text_liquid_fill.dart @@ -55,6 +55,9 @@ class TextLiquidFill extends StatefulWidget { /// By default, the animation will load to 1.0 (100%). final double loadUntil; + /// Adds the onFinished [VoidCallback] to the animated widget. + final VoidCallback? onFinished; + TextLiquidFill({ Key? key, required this.text, @@ -68,6 +71,7 @@ class TextLiquidFill extends StatefulWidget { this.boxBackgroundColor = Colors.black, this.waveColor = Colors.blueAccent, this.loadUntil = 1.0, + this.onFinished, }) : assert(loadUntil > 0 && loadUntil <= 1.0), super(key: key); @@ -97,6 +101,19 @@ class _TextLiquidFillState extends State vsync: this, duration: widget.loadDuration, ); + + //If exist, call onFisihed callback on animation end and remove listener. + if (widget.onFinished != null) { + late Callback statusListener; + statusListener = (status) { + if (status == AnimationStatus.completed) { + widget.onFinished?.call(); + _loadController.removeStatusListener(statusListener); + } + }; + _loadController.addStatusListener(statusListener); + } + _loadValue = Tween( begin: 0.0, end: widget.loadUntil, @@ -215,3 +232,5 @@ class _WavePainter extends CustomPainter { return true; } } + +typedef Callback = void Function(AnimationStatus);