observe method

void observe(
  1. LicenseValidation licenseValidation,
  2. Observer observer, {
  3. ObserverPolicy policy = ObserverPolicy.always,
})

Implementation

void observe(LicenseValidation licenseValidation, Observer observer,
    {ObserverPolicy policy = ObserverPolicy.always}) {
  bool notified = true;
  switch (licenseValidation.stateMachine.state.runtimeType) {
    case ValidState:
      observer((licenseValidation.stateMachine.state as ValidState).documents,
          null);
      break;
    case FailureState:
      observer(
          null, (licenseValidation.stateMachine.state as FailureState).error);
      break;
    case CancelledState:
      observer(null, null);
      break;
    default:
      notified = false;
  }
  if (notified && policy != ObserverPolicy.always) {
    return;
  }
  observers.add(Product2(observer, policy));
}