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() {
  membersScrollController.addListener(_scrollListener);

  name = TextFieldState(
    text: chat?.chat.value.name?.val,
    onFocus: (s) async {
      if (s.text.isNotEmpty) {
        try {
          ChatName(s.text);
        } on FormatException {
          s.error.value = 'err_incorrect_input'.l10n;
        } catch (e) {
          s.error.value = e.toString();
        }
      }
    },
  );

  _fetched?.finish();
  _fetched = _ready.startChild('fetch');

  try {
    final FutureOr<RxChat?> fetched = _chatService.get(chatId);

    if (fetched is RxChat?) {
      _applyChat(fetched);
    } else {
      status.value = RxStatus.loading();
      fetched.then(_applyChat);
    }
  } catch (e) {
    _ready.throwable = e;
    _ready.finish(status: const SpanStatus.internalError());
    rethrow;
  }

  super.onInit();
}