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() {
  password = TextFieldState(
    onChanged: (s) {
      password.error.value = null;

      if (s.text.isNotEmpty) {
        try {
          UserPassword(s.text);
        } on FormatException {
          s.error.value = 'err_password_incorrect'.l10n;
        }
      }
    },
    onSubmitted: (s) async {
      if (s.error.value != null || s.status.value.isLoading) {
        return;
      }

      s.editable.value = false;
      s.status.value = RxStatus.loading();

      try {
        final List<Future> futures =
            sessions
                .map(
                  (e) => _authService.deleteSession(
                    id: e.id,
                    password: UserPassword(s.text),
                  ),
                )
                .toList();

        await Future.wait(futures);

        stage.value = DeleteSessionStage.done;
      } on DeleteSessionException catch (e) {
        s.error.value = e.toMessage();
      } catch (e) {
        s.error.value = 'err_data_transfer'.l10n;
        rethrow;
      } finally {
        s.status.value = RxStatus.empty();
        s.editable.value = true;
      }
    },
  );

  super.onInit();
}