Back to Blog

Rebuild Less in Flutter: Provider's Selector and Riverpod's select

Dev Notes · Published November 17, 2026

Your screen watches a state object with ten fields. One field changes, and the whole screen rebuilds. Most of the time Flutter is fast enough that you don’t notice. On a long list, a chart, or state that changes many times a second, you do.

The fix is to select only the value a widget needs. Provider has Selector and context.select. Riverpod has ref.watch(provider.select(...)). This post shows both, because a lot of apps still run on Provider (I see it in almost every app I take over) and new ones use Riverpod.

I first wrote about Selector in 2021. This is the updated version, with null safety, Dart 3 records and Riverpod.

The problem: one change rebuilds everything

A ChangeNotifier with two counters:

class Counters extends ChangeNotifier {
  int _a = 0;
  int _b = 0;
  int get a => _a;
  int get b => _b;

  void incrementA() {
    _a++;
    notifyListeners();
  }

  void incrementB() {
    _b++;
    notifyListeners();
  }
}

And a screen that shows both with a Consumer:

Consumer<Counters>(
  builder: (context, counters, child) {
    debugPrint('rebuild both');
    return Column(
      children: [
        Text('A: ${counters.a}'),
        Text('B: ${counters.b}'),
      ],
    );
  },
)

Tap “increment A” and both texts rebuild. notifyListeners() says “something changed”, not what, so every listener runs again.

Provider: Selector

Selector<T, S> takes the provider T, picks a value S, and rebuilds only when S changes:

Column(
  children: [
    Selector<Counters, int>(
      selector: (_, counters) => counters.a,
      builder: (context, a, child) => Text('A: $a'),
    ),
    Selector<Counters, int>(
      selector: (_, counters) => counters.b,
      builder: (context, b, child) => Text('B: $b'),
    ),
  ],
)

Now “increment A” rebuilds only the first Text. Every time the provider notifies, Selector runs your selector function and compares the result with the previous one. Same value, no rebuild.

context.select: the shorter way

Inside a widget’s build, context.select does the same thing without the extra widget:

class CounterAText extends StatelessWidget {
  const CounterAText({super.key});

  @override
  Widget build(BuildContext context) {
    final a = context.select<Counters, int>((c) => c.a);
    return Text('A: $a');
  }
}

The catch: it rebuilds the whole widget it’s called in. So put it in a small widget, like this one, not at the top of a big screen.

Don’t forget the child parameter

Consumer and Selector both take a child that’s built once and passed back into builder. Use it for the parts that never change:

Selector<Counters, int>(
  selector: (_, c) => c.a,
  builder: (context, a, child) => Row(children: [child!, Text('$a')]),
  child: const ExpensiveIcon(),   // not rebuilt when a changes
)

Riverpod: select

In Riverpod, select works on any provider, in widgets and inside other providers:

class CounterAText extends ConsumerWidget {
  const CounterAText({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final a = ref.watch(countersProvider.select((s) => s.a));
    return Text('A: $a');
  }
}

The widget rebuilds only when s.a changes. The new value is compared with ==.

Select inside providers too

This is where I use it most. In Sundry, several providers only care who is signed in, not the rest of the user object:

@Riverpod(keepAlive: true)
class DriveSuggestionDismissed extends _$DriveSuggestionDismissed {
  @override
  Future<bool> build() async {
    // Rebuild for whoever signs in next, and only then.
    ref.watch(currentUserProvider.select((u) => u?.id));
    // ...read this user's saved preference
  }
}

The user object changes more often than the id (profile edits, session refreshes). Selecting the id means this provider, and everything that depends on it, only reruns when a different person signs in. Sundry does this in 14 files.

Async providers

On an async provider you’re selecting from an AsyncValue:

// In a widget: rebuild only when the name changes (null while loading)
final name = ref.watch(profileProvider.select((p) => p.value?.name));

Inside another provider, selectAsync lets you await one field:

@riverpod
Future<String> greeting(Ref ref) async {
  final name = await ref.watch(profileProvider.selectAsync((p) => p.name));
  return 'Hi $name';
}

Select several fields with a record

Dart 3 records compare by value, which makes them perfect for selecting more than one field:

final (name, total) = ref.watch(
  invoiceProvider.select((i) => (i.clientName, i.total)),
);

The widget rebuilds when the client name or the total changes, and ignores every other field on the invoice. The same trick works with Selector and context.select in Provider.

The pitfall: selecting a new object every time

// ✗ rebuilds on every change: map().toList() makes a new list each time,
//   and two different List objects are never ==
final ids = ref.watch(receiptsProvider.select(
  (r) => r.map((e) => e.id).toList(),
));

select compares with ==. A new List is never equal to the previous one, even with the same items, so this rebuilds every time and you’ve gained nothing. Options:

  • Select something with value equality: a primitive, a record, an enum, or a Freezed class (Freezed generates == that compares fields, including lists).
  • Select a count or a hash instead of the list, if that’s all the widget needs.
  • Move the calculation into its own provider and watch that provider.

(Provider’s Selector compares collections by content by default, so this specific case hurts less there. Don’t rely on it for your own classes.)

Provider to Riverpod cheat sheet

Useful when moving an older app over:

Provider Riverpod
Consumer<T> / context.watch<T>() ConsumerWidget + ref.watch(tProvider)
Selector<T, S> / context.select<T, S>(...) ref.watch(tProvider.select((t) => ...))
context.read<T>() in a callback ref.read(tProvider) / ref.read(tProvider.notifier)
ChangeNotifier + notifyListeners() Notifier / AsyncNotifier with immutable state

For the full Riverpod setup I use, see Riverpod + Freezed + build_runner.

Don’t optimize blindly

  • Measure first. Open Flutter DevTools, turn on rebuild tracking, and look for widgets that rebuild far more than you expect. Fix those.
  • Split widgets before reaching for select. A small widget with a const constructor is often all you need.
  • Use select where it pays: long lists, charts, animations, and state that changes often. On a settings screen that rebuilds once per tap, it isn’t worth the extra code.

Takeaways

  • Consumer, context.watch and plain ref.watch rebuild on any change to the provider.
  • Selector, context.select and ref.watch(p.select(...)) rebuild only when the selected value changes.
  • Select primitives, records or Freezed objects, never a freshly built list.
  • In Riverpod, use select inside providers too, so whole chains of providers don’t rerun.

Hooks pair well with this for local widget state: see Flutter Hooks with Riverpod.