Flutter animation value resetting on provider state update

189 views
Skip to first unread message

Olayemi Garuba

unread,
Nov 5, 2020, 9:02:23 AM11/5/20
to Flutter Development (flutter-dev)

I am making a stepper widget and I have been able to make all parts of it, however I plan on updating a state value from my provider after the animation runs, this has not been possible because whenever I make my provider state update, the initState method is run which in turn resets my animation.

This is the content of my initState() method:

Screenshot 2020-11-05 at 14.59.52.png

And this is how I begin the animation

Screenshot 2020-11-05 at 15.00.00.png

Everything works fine but whenever the AnimationStatus is completed and I try to make the provider state update, the animation.value value goes back to the initial value and I can see initState being called again.

If I remove the call to notifyListeners() from my provider's setter, then the animation value doesn't get reset, however I need the new value to be updated.

How can I retain this value after the provider state update?

This is a link to my question on stackoverflow: https://stackoverflow.com/questions/64698468/flutter-animation-value-resetting-on-provider-state-update

Andy Greenshaw

unread,
Nov 5, 2020, 9:05:26 AM11/5/20
to Flutter Development (flutter-dev), Olayemi Garuba
if you sent code rather than images, more people would help.
On Nov 5, 2020, 2:02 PM +0000, Olayemi Garuba <olayemii...@gmail.com>, wrote:

I am making a stepper widget and I have been able to make all parts of it, however I plan on updating a state value from my provider after the animation runs, this has not been possible because whenever I make my provider state update, the initState method is run which in turn resets my animation.

This is the content of my initState() method:

<Screenshot 2020-11-05 at 14.59.52.png>



And this is how I begin the animation

<Screenshot 2020-11-05 at 15.00.00.png>

Everything works fine but whenever the AnimationStatus is completed and I try to make the provider state update, the animation.value value goes back to the initial value and I can see initState being called again.

If I remove the call to notifyListeners() from my provider's setter, then the animation value doesn't get reset, however I need the new value to be updated.

How can I retain this value after the provider state update?

This is a link to my question on stackoverflow: https://stackoverflow.com/questions/64698468/flutter-animation-value-resetting-on-provider-state-update

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/9db16750-ab7a-4a01-8579-270d992ae8afn%40googlegroups.com.

Suzuki Tomohiro

unread,
Nov 5, 2020, 9:22:09 AM11/5/20
to Olayemi Garuba, Flutter Development (flutter-dev)
My wild guess: something is listening the LanguageProvider and recreates widgets upon notifyListener. Add breakpoints to see who are notified upon notifyListeners.

Olayemi Garuba

unread,
Nov 5, 2020, 9:29:40 AM11/5/20
to Flutter Development (flutter-dev)
Yes, LanguageProvider has a listener on the parent widget for the whole application. I need it in order to know the current locale whenever updated.

Suzuki Tomohiro

unread,
Nov 5, 2020, 9:54:07 AM11/5/20
to Flutter Development (flutter-dev)
Good. Now the question is down to why the stateful widget is recreated when the parent widget was notified. Maybe it involves a Key (GlobalKey, LocalKey, etc.)?

Reply all
Reply to author
Forward
0 new messages