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

To view or add a comment, sign in

More articles by Mike Matiunin

  • Business Logic Component [4 of 4]

    In this final article of the BLoC series, we will look at code examples and practical implementation of several popular…

  • Business Logic Component [3 of 4]

    In the third part of a series of articles about the bloc, we will analyze successful and unsuccessful decisions…

  • Harness the Power of Anonymous Functions in Dart

    Anonymous functions, also known as lambda expressions or closures, are an essential part of modern programming…

  • Handling Asynchronous Dependencies in Flutter & Dart

    In Flutter and Dart applications, it is common to encounter scenarios where a class depends on an asynchronous…

    2 Comments
  • Business Logic Component [1 of 4]

    Introduction You can find the full original article here. We are starting a series of articles about Business Logic…

  • Business Logic Component [2 of 4]

    The second article is from a series of articles about BLoC. You can find the full article here.

  • Anti-patterns of error handling in dart

    This article will show common pitfalls you can make when handling exceptions and how to do it right. The article will…

  • Layer link

    Let’s take a look at how to create and display widgets that appear on top of other widgets and follow them when moved…

    1 Comment

Insights from the community

Others also viewed

Explore topics