debugCheckInvalidValueType property

void Function<T>(T value) debugCheckInvalidValueType
read / write

A sanity check to prevent misuse of Provider when a variant should be used instead.

By default, debugCheckInvalidValueType will throw if value is a Listenable or a Stream. In release mode, debugCheckInvalidValueType does nothing.

You can override the default behavior by "decorating" the default function.
For example if you want to allow rxdart's Subject to work on Provider, then you could do:

void main() {
 final previous = Provider.debugCheckInvalidValueType;
 Provider.debugCheckInvalidValueType = <T>(value) {
   if (value is Subject) return;
   previous<T>(value);
 };

 // ...
}

This will allow Subject, but still allow Stream/Listenable.

Alternatively you can disable this check entirely by setting debugCheckInvalidValueType to null:

void main() {
  Provider.debugCheckInvalidValueType = null;
  runApp(MyApp());
}

Implementation

static void Function(T value) debugCheckInvalidValueType = (T value) {
  assert(() {
    if (value is Listenable || value is Stream) {
      throw FlutterError('''
Tried to use Provider with a subtype of Listenable/Stream ($T).

This is likely a mistake, as Provider will not automatically update dependents
when $T is updated. Instead, consider changing Provider for more specific
implementation that handles the update mechanism, such as:

- ListenableProvider
- ChangeNotifierProvider
- ValueListenableProvider
- StreamProvider

Alternatively, if you are making your own provider, consider using InheritedProvider.

If you think that this is not an error, you can disable this check by setting
Provider.debugCheckInvalidValueType to `null` in your main file:

```
void main() {
Provider.debugCheckInvalidValueType = null;

runApp(MyApp());
}
```
''');
    }
    return true;
  }());
}