build method

  1. @override
Future<void> build(
  1. BuildTrigger trigger
)
override

Recalculates the state of the repository.

This method is called when:

Override this method to handle changes from said repositories.


Example:

class MyRepository extends Repository<MyState> {
  final OtherRepository _otherRepository;

  MyRepository(this._otherRepository) : super(MyState.new) {
    watch(_otherRepository);
  }

  @override
  FutureOr<void> build(BuildTrigger trigger) async {
    if(trigger is InitialBuildTrigger) {
      // Do something when the repository is first initialized
    }

    if(trigger is UpdateTrigger) {
      // Do something when the repository is updated
    }

    if(trigger is OtherRepository) {
      // Do something when the other repository emits a new state
    }
  }
}

Implementation

@override
Future<void> build(BuildTrigger trigger) async {
  // We don't need to refresh the plan as it's only loosely connected to the tasks.
  if (trigger is MoodleTasksRepository) {
    log('Skipping refresh triggered by $trigger');

    return;
  }

  await _loadPlan(waitForData(_auth));
}