


# updateEmail method




    *[<Null safety>](https://dart.dev/null-safety)*




[FutureOr](https://api.flutter.dev/flutter/dart-async/FutureOr-class.html)&lt;void> updateEmail
()





<p>Update or add <code>email</code>.</p>
<p>Throws a UpdateEmailFailureInterface if
an exception occurs.</p>



## Implementation

```dart
FutureOr<void> updateEmail() async {
  if (state.status.isSubmissionInProgress) {
    return;
  }

  if (!state.status.isValidated) {
    return;
  }

  final form = formRepository.accessForm(formName);
  emit(
    EditAccountState(
      form: form,
      status: FormStatus.submissionInProgress,
    ),
  );

  final email = form.valueOf<String?>(AuthFormField.email);

  if (email.isNullOrEmpty) {
    emit(
      EditAccountState(
        form: form,
        errorMessage: 'An error occured while retrieving data from the form.',
        status: FormStatus.submissionFailure,
      ),
    );
  }

  return CustomRoutine<Account, Data?>(
    routine: () => authenticationRepository.updateEmail(
      email: email!,
    ),
    attachedLogic: (routineResult) => onEmailUpdated(
      routineResult,
      form,
    ),
    onError: (error) {
      emit(
        EditAccountState(
          form: form,
          errorMessage: error.message,
          status: FormStatus.submissionFailure,
        ),
      );
      addError(error);
    },
    onSuccess: (account, data) {
      authenticationRepository.addSession(
        SessionWrapper(
          event: UpdatedEvent(account: account),
          session: Session<Data>(
            account: account,
            data: data,
          ),
        ),
      );
      emit(
        EditAccountState(
          form: form,
          status: FormStatus.submissionSuccess,
        ),
      );
    },
  ).call();
}
```







