flutterdartriverpodflutter-hooks

Dispose hook on widget rebuild


Do hooks dispose of themselves when a widget rebuilds? Is it possible to cause this behavior?

I'm using Riverpod for state management and I have a widget that creates a custom TextEditingController hook in the build method. When I update my widget's state (in Riverpod) the widget correctly rebuilds but it seems to retain the old TextEditingController hook. Is it possible to automatically dispose of and recreate it?

Thanks!


Solution

  • The text controller will be disposed of as expected:

    enter image description here

    Therefore, nothing needs to be done.