submitName method

Future<void> submitName()

Submits the name field.

Implementation

Future<void> submitName() async {
  name.focus.unfocus();

  if (name.text == contact.value?.contact.value.name.val) {
    name.unsubmit();
    nameEditing.value = false;
    return;
  }

  UserName? userName;
  try {
    userName = UserName(name.text);
  } on FormatException catch (_) {
    name.status.value = RxStatus.empty();
    name.error.value = 'err_incorrect_input'.l10n;
    name.unsubmit();
    return;
  }

  if (name.error.value == null || name.resubmitOnError.isTrue) {
    name.status.value = RxStatus.loading();
    name.editable.value = false;

    try {
      await _contactService.changeContactName(contact.value!.id, userName);
      name.error.value = null;
      nameEditing.value = false;
      name.unsubmit();
    } on UpdateChatContactNameException catch (e) {
      name.error.value = e.toString();
    } catch (e) {
      name.resubmitOnError.value = true;
      name.error.value = 'err_data_transfer'.l10n;
      rethrow;
    } finally {
      name.status.value = RxStatus.empty();
      name.editable.value = true;
    }
  }
}