ListenableProvider<T extends Listenable> constructor

ListenableProvider<T extends Listenable>(
  1. {Key key,
  2. @required Create<T> create,
  3. Dispose<T> dispose,
  4. bool lazy,
  5. TransitionBuilder builder,
  6. Widget child}
)

Creates a Listenable using create and subscribes to it.

dispose can optionally passed to free resources when ListenableProvider is removed from the tree.

create must not be null.

Implementation

ListenableProvider({
  Key key,
  @required Create<T> create,
  Dispose<T> dispose,
  bool lazy,
  TransitionBuilder builder,
  Widget child,
})  : assert(create != null),
      super(
        key: key,
        startListening: _startListening,
        create: create,
        dispose: dispose,
        debugCheckInvalidValueType: kReleaseMode
            ? null
            : (value) {
                if (value is ChangeNotifier) {
                  // ignore: invalid_use_of_protected_member
                  assert(!value.hasListeners, '''
The default constructor of ListenableProvider/ChangeNotifierProvider
must create a new, unused Listenable.

If you want to reuse an existing Listenable, use the second constructor:

- DO use ChangeNotifierProvider.value to provider an existing ChangeNotifier:

MyChangeNotifier variable;
ChangeNotifierProvider.value(
value: variable,
child: ...
)

- DON'T reuse an existing ChangeNotifier using the default constructor.

MyChangeNotifier variable;
ChangeNotifierProvider(
create: (_) => variable,
child: ...
)
''');
                }
              },
        lazy: lazy,
        builder: builder,
        child: child,
      );