ChangeNotifier selector
Mike Matiunin
Flutter Lead Software Engineer | Expert in Dart, Full-Stack Development & DevOps | Open Source Contributor
Have you had a situation where you must select and rebuild the interface only to change specific fields of your?ChangeNotifier?
Not convenient to use?AnimatedBuilder?with ChangeNotifier instead of?ValueListenableBuilder?
Of course, I had to. So I made a simple extension that converts ChangeNotifier to?ValueListenable?and has filtering capabilities.
And transformation pipeline looks like this:
ChangeNotifier --- select & filter --> ValueListenable<Value>
For example, you can transform your AppModel and rebuild some parts of widgets when localization is changed and only when the language code has changed:
ValueListenableBuilder<Locale>(
valueListenable: appModel.select<Locale>(
(cn) => cn.locale,
(prev, next) => prev.languageCode != next.languageCode
),
builder: (context, locale, child) => Text(locale),
)