flutter_hooks icon indicating copy to clipboard operation
flutter_hooks copied to clipboard

Add hook to observe `didChangeDependencies`

Open water-mizuu opened this issue 1 year ago • 0 comments
trafficstars

Is your feature request related to a problem? Please describe. Basically, I have a complicated [Widget] which uses [didChangeDependencies] to update state intricately. This involves animations, and with it, comes asynchronous functions. I would like to allow hooks to listen to lifecycle method [didChangeDependencies] as hooks can to [initState] and [dispose], additionally helping parallel the [State] object of [Widgets].

Now, why wouldn't it be applicable to being put in [build] instead? Because I don't want [didChangeDependencies], (and the code inside it) to be run on every [setState]. It should only run when the dependencies it has from providers update.

Describe the solution you'd like As described above, just modify the [HookElement] mixin to allow listening to [didChangeDependencies] on each hook. I could do this on a local version of the library, but it would be nice to have it as an official change.

Describe alternatives you've considered None.

water-mizuu avatar Nov 30 '23 12:11 water-mizuu