Notifier<S> constructor

Notifier<S>(
  1. S state
)

Creates a Notifier with the given initial state.

state is the initial state value for the notifier.

Example:

class CounterNotifier extends Notifier<int> {
  CounterNotifier() : super(0); // Start with initial state of 0
}

Dependencies must be reachable before onInit runs.

Dart runs a superclass constructor body before the subclass's, and this constructor starts onInit. A field assigned in the subclass's own constructor body is therefore still unset inside onInit. Pass dependencies as initializing formals or assign them in the initializer list:

class UserNotifier extends Notifier<User?> {
  UserNotifier(this.repository) : super(null);

  final UserRepository repository;

  @override
  void onInit() => load();
}

Implementation

Notifier(super.state) {
  _initialize();
}