AutoDisposeAsyncNotifierProviderImpl<NotifierT extends AsyncNotifierBase<T>, T> constructor

AutoDisposeAsyncNotifierProviderImpl<NotifierT extends AsyncNotifierBase<T>, T>(
  1. NotifierT _createNotifier(), {
  2. String? name,
  3. Iterable<ProviderOrFamily>? dependencies,
  4. @Deprecated('Will be removed in 3.0.0') Family<Object?>? from,
  5. @Deprecated('Will be removed in 3.0.0') Object? argument,
  6. @Deprecated('Will be removed in 3.0.0') DebugGetCreateSourceHash? debugGetCreateSourceHash,
})

A class which exposes a state that can change over time.

For example, Notifier can be used to implement a counter by doing:

final counterProvider = NotifierProvider<Counter, int>(Counter.new);

class Counter extends Notifier<int> {
  @override
  int build() {
    // Inside "build", we return the initial state of the counter.
    return 0;
  }

  void increment() {
    state++;
  }
}

We can then listen to the counter inside widgets by doing:

Consumer(
  builder: (context, ref) {
    return Text('count: ${ref.watch(counterProvider)}');
  },
)

And finally, we can update the counter by doing:

Consumer(
  builder: (context, ref) {
    return ElevatedButton(
      onTap: () => ref.read(counterProvider.notifier).increment(),
      child: const Text('increment'),
    );
  },
)

The state of Notifier is expected to be initialized synchronously. For asynchronous initializations, see AsyncNotifier.

Implementation

AutoDisposeAsyncNotifierProviderImpl(
  super._createNotifier, {
  super.name,
  super.dependencies,
  @Deprecated('Will be removed in 3.0.0') super.from,
  @Deprecated('Will be removed in 3.0.0') super.argument,
  @Deprecated('Will be removed in 3.0.0') super.debugGetCreateSourceHash,
}) : super(
        allTransitiveDependencies:
            computeAllTransitiveDependencies(dependencies),
      );