onInit method

  1. @override
void onInit()
override

Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.

Implementation

@override
void onInit() {
  hasPassword = RxBool(myUser.value?.hasPassword ?? false);

  password = TextFieldState(
    onChanged: (_) => repeat.error.value = null,
    onFocus: (s) {
      if (s.text.isNotEmpty) {
        try {
          UserPassword(s.text);
        } on FormatException {
          s.error.value = 'err_password_incorrect'.l10n;
        }
      }

      if (s.error.value == null &&
          repeat.text.isNotEmpty &&
          password.text.isNotEmpty &&
          password.text != repeat.text) {
        repeat.error.value = 'err_passwords_mismatch'.l10n;
      }
    },
    onSubmitted: (s) {
      repeat.focus.requestFocus();
      s.unsubmit();
    },
  );

  repeat = TextFieldState(
    onFocus: (s) {
      if (s.text.isNotEmpty) {
        try {
          UserPassword(s.text);
        } on FormatException {
          s.error.value = 'err_password_incorrect'.l10n;
        }
      }

      if (s.error.value == null &&
          repeat.text.isNotEmpty &&
          password.text.isNotEmpty &&
          password.text != repeat.text) {
        repeat.error.value = 'err_passwords_mismatch'.l10n;
      }
    },
    onSubmitted: (s) => setPassword(),
  );

  super.onInit();
}