1

Trying to create a simple countdown timer animation in Flutter.

I have used the StepTween class along with an AnimatedController to achieve the animation using the following:

Flutter - Create a countdown widget.

However, what I am trying to accomplish looks something like this:

enter image description here

I tried creating a Row widget and adding a Text() followed by AnimatedWidget(). However the styling is nowhere near the expected result:

enter image description here

  1. How do I get the size/color for the text within the AnimatedWidget() to match the design?
  2. The AnimatedWidget() switches to a single digit within the 0-10 region. For example instead of showing the countdown as 0:09 it is shown as 0:9. How do I change that?

Thanks!

user2511882
  • 9,022
  • 10
  • 51
  • 59

1 Answers1

1

In countdown widget

 child: new Text(val.toString(), style: new TextStyle(fontSize: 150.0)),

is responsible for the styling you see. Instead try removing the style or apply the theme:

 child: new Text(val.toString(), style: Theme.of(context).textTheme.body1),
Denis G
  • 511
  • 4
  • 11
  • Not sure what are you pointing at here. Could you elaborate on that please? – user2511882 Dec 19 '19 at 19:17
  • In your original post asked "How do I get the size/color for the text within the AnimatedWidget() to match the design?". If you look at the source code of your custom class which extends AnimatedWidget, that is the part that determines the styling of the counter. If you want a default text style of your app's Theme you can remove the style parameter from the Text widget showing the counter. If you want it changed, then you can do it right there or link from the Theme (https://flutter.dev/docs/cookbook/design/themes). – Denis G Dec 19 '19 at 19:31
  • That fixed the first issue. Any clue about the second query? – user2511882 Dec 23 '19 at 14:03
  • To add a leading zero you can change: child: new Text(val.toString()), to: child: new Text(val.toString().padLeft(2, '0')), – Denis G Dec 23 '19 at 18:06
  • That worked! Thank you so much. Would you be open to doing a collab on a project if needed? – user2511882 Dec 23 '19 at 19:59
  • Happy to hear that my solution worked for you. I'm staying busy, but may be open to new endeavors. Ping me when you have new ideas. – Denis G Dec 23 '19 at 21:13