Description
Right now, we are rebuilding the UI based on the different settings (properties) of PerAccountStore
, a ChangeNotifier
injected into the widget tree through an InheritedNotifier
widget.
I have noticed that unnecessary rebuilds often happen when a property of PerAccountStore
changes, and because notifyListeners
is called, all the registered build
methods are called, even if they do not care about that specific property. I have examined this by putting some log
statements in ComposeBox.build
and _MessageListPageState.build
methods both of which have a dependency on PerAccountStore
by calling PerAccountStoreWidget.of(context)
. I then went to the web app and changed the time format settings for my account, which is PerAccountStore.userSettings
in the codebase, a property that is not needed in the build
methods mentioned above at the moment. This change of settings resulted in those unrelated build
methods being called. There are numerous other places where such unnecessary rebuilds happen.
We could implement this granular control of listening from scratch, or we can use a third-party package. One of those packages I would recommend is Provider. When using this package, we can do something like this:
context.select<PerAccountStore, Map<int, User>>((store) => store.users);
context.select<PerAccountStore, UserSettings?>((store) => store.userSettings);
This will re-call the build
methods only when the specified properties are changed.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status