notifyListeners method

  1. @override
void notifyListeners()

Notify dependents that this provider has changed.

This is typically used for mutable state, such as to do:

class TodoList extends Notifier<List<Todo>> {
  @override
  List<Todo>> build() => [];

  void addTodo(Todo todo) {
    state.add(todo);
    ref.notifyListeners();
  }
}

Implementation

@override
void notifyListeners() {
  _throwIfInvalidUsage();

  if (_element._didBuild) {
    final currentValue = _element.value;
    final currentValueResult = _element.resultForValue(currentValue);

    _element._notifyListeners(
      next: currentValueResult!,
      previous: currentValueResult,
      updateShouldNotifyResult: null,
    );
  }
}