runBuild method

  1. @$mustCallSuper
  2. @override
void runBuild()
inherited

Executes Notifier.build.

This is called by Riverpod, and should not be called manually. The purpose of this method is to allow mixins to perform logic before/after the build method of a notifier.

For example, you could implement a mixin that logs state changes:

mixin LoggingMixin<T> on AnyNotifier<T> {
  @override
  void runBuild() {
    print('Will build $this');
    super.runBuild();
    print('Did build $this');
  }
}

The benefit of this method is that it applies on all notifiers, regardless of whether they use arguments or not.

Implementation

@$mustCallSuper
@override
void runBuild() {
  final created = build();
  final ref = this.ref as $Ref<String?, String?>;
  final element = ref.element as $ClassProviderElement<
      AnyNotifier<String?, String?>, String?, Object?, Object?>;
  element.handleValue(ref, created);
}