uni icon indicating copy to clipboard operation
uni copied to clipboard

Refactor LazyConsumer

Open DGoiana opened this issue 8 months ago • 2 comments

Refactor LazyConsumer to start using FutureBuilder and Completer instead of addPostFrameCallback, which is much more reliable and testable.

Without Completer and FutureBuilder, LazyConsumer immediately builds the widget before ensuring that the provider is actually initialized. It shows the state of the provider, which can be, at the time, empty or incorrect. Later, after addPostFrameCallback, it initializes the provider asynchronously. By the time the provider finishes initializing, the widget might already have built once or even multiple times unnecessarily.

With Completer and FutureBuilder, the widget starts by waiting for the Future to complete. Only after the provider initialization completes, the main content builds properly, without unnecessary intermediate rebuilds.

DGoiana avatar Apr 28 '25 21:04 DGoiana

You can also take a look into this: https://api.flutter.dev/flutter/widgets/StreamBuilder-class.html

DGoiana avatar May 13 '25 16:05 DGoiana

After this, take a look into #1599

DGoiana avatar May 13 '25 16:05 DGoiana