riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

Add a mechanism to pause rebuild widget when using ref.watch

Open lcdsmao opened this issue 3 years ago • 2 comments
trafficstars

Is your feature request related to a problem? Please describe. Assume we have a StateNotifierProvider fooProvider. Mulitple pages depend on fooProvider. If we have a deep back stack like: PageA -> PageB -> PageC -> PageD and all of these pages depend on fooProvider via ref.watch(fooProvider). Then any state change of fooProvider will rigger all of these pages rebuild, which has a performance problem.

Describe the solution you'd like I am thinking of providing a new widget that can control the ref.watch behavior in the widget subtree (inspired by TickerMode). The enable/disable logic can be implemented by ourselves or by riverpod if possible. For example, control via the VisibilityDetector.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

lcdsmao avatar Feb 18 '22 01:02 lcdsmao

Would it be alright to use TickerMode directly instead of adding something new? Such that when tickers are muted, ref.watch subscriptions are paused too

rrousselGit avatar Feb 27 '22 15:02 rrousselGit

Would it be alright to use TickerMode directly instead of adding something new?

Sounds good! I hadn't noticed TickerMode was used in Overlay and other widgets before searching the flutter repo.

lcdsmao avatar Feb 28 '22 04:02 lcdsmao