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:

  valueListenable: appModel.select<Locale>(
    (cn) => cn.locale,
    (prev, next) => prev.languageCode != next.languageCode
  builder: (context, locale, child) => Text(locale),

Complete code of my extension:

More from Plague Fox
Linter, Analyzer & Dart Code Metrics
Dart Flutter Podcast Russian

Linter, Analyzer & Dart Code Metrics

Join us in this stream where we will take a detailed look at Dart and Flutter tools such as linter, analyzer, and Dart Code Metrics. We will discuss how these tools help improve code quality and enhance its readability, as well as how they can make your development more efficient.
Plague Fox

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.