SelectContext extension

Depends on a part of what a provider above provides.

A widget built again when the theme changes, not when the user does:

Builder(
  builder: (context) {
    final dark = context.select((Settings s) => s.dark);
    return Text(dark ? 'Dark' : 'Light');
  },
)
on

Methods

select<T, R>(R selector(T value)) → R

Available on BuildContext, provided by the SelectContext extension

What selector picks from the T of the nearest provider of one above this context, which is rebuilt only when a change of the value makes selector pick something else: not ==, lists, sets, maps and other iterables compared element by element. A build may select any number of parts, of one value or of several; each build selects anew. A ProviderNotFoundException if there is none, unless T is nullable.