Dart Flutter Article

ChangeNotifier selector

Article about how to select a value from the ChangeNotifier and transform it to a ValueListenable
Plague Fox 1 min read
ChangeNotifier selector
ChangeNotifier selector

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),
)

Complete code of my extension:

Share
Comments
More from Plague Fox
Form State Management
Dart Flutter Article Tips

Form State Management

Flutter's SDK already has everything you need to manage complex forms — no packages required. Listenable.merge turns any combination of ValueNotifier, TextEditingController, FocusNode, and ChangeNotifier into a single reactive form controller.
Plague Fox 4 min read
Safe Resource Cleanup with Closure Chains
Dart Flutter Article

Safe Resource Cleanup with Closure Chains

Dart has no defer, no RAII, no scope guards. When multi-step async initialization fails midway, you need to unwind only what was set up — in reverse order, crash-safe. Here's a 6-line closure chain pattern that gives you transactional init, safe teardown, and cancellation support for free.
Plague Fox 5 min read

Plague Fox

Engineer by day, fox by night. Talks about Flutter & Dart.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Plague Fox.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.