From 38b2fe1ff8d25c09f645674308a7d4f0cbd8b099 Mon Sep 17 00:00:00 2001 From: ertgrulll Date: Sun, 4 Jul 2021 02:51:01 +0300 Subject: [PATCH 1/2] Added onFinished callback to TextLiquidFill, updated readme, updated example --- README.md | 5 ++++- example/lib/main.dart | 3 +++ lib/src/text_liquid_fill.dart | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) 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..4be3196 100644 --- a/lib/src/text_liquid_fill.dart +++ b/lib/src/text_liquid_fill.dart @@ -1,6 +1,13 @@ +import "dart:async"; import 'dart:math'; import 'package:flutter/material.dart'; +void main() { + var counterStream = + Stream.periodic(const Duration(seconds: 1), (x) => x).take(15); + counterStream.forEach(print); +} + /// Animation that displays a [text] element, coloring it to look like sloshing /// water is filling it up. /// @@ -55,6 +62,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 +78,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 +108,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 +239,5 @@ class _WavePainter extends CustomPainter { return true; } } + +typedef Callback = void Function(AnimationStatus); From f64bfb8df82f444da19e2e3567dc7fed8d1e5bfb Mon Sep 17 00:00:00 2001 From: ertgrulll <65064049+ertgrulll@users.noreply.github.com> Date: Sun, 4 Jul 2021 06:01:03 +0300 Subject: [PATCH 2/2] Update text_liquid_fill.dart --- lib/src/text_liquid_fill.dart | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/src/text_liquid_fill.dart b/lib/src/text_liquid_fill.dart index 4be3196..7bd02dd 100644 --- a/lib/src/text_liquid_fill.dart +++ b/lib/src/text_liquid_fill.dart @@ -1,13 +1,6 @@ -import "dart:async"; import 'dart:math'; import 'package:flutter/material.dart'; -void main() { - var counterStream = - Stream.periodic(const Duration(seconds: 1), (x) => x).take(15); - counterStream.forEach(print); -} - /// Animation that displays a [text] element, coloring it to look like sloshing /// water is filling it up. ///