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() {
  scrollController.addListener(_updateScrollPosition);

  _nextInterval = interval(
    _scrollPosition,
    (_) => _next(),
    time: const Duration(milliseconds: 100),
    condition:
        () =>
            scrollController.hasClients &&
            (scrollController.position.pixels >
                scrollController.position.maxScrollExtent - 500),
  );

  search = TextFieldState(onFocus: (d) => query.value = d.text);
  _searchDebounce = debounce(query, (q) => _search(q.trim()));
  _searchWorker = ever(query, (String q) {
    if (q.length < 2) {
      _usersSearchSubscription?.cancel();
      usersSearch.value = null;
      _contactsSearchSubscription?.cancel();
      contactsSearch.value = null;
      users.clear();
      contacts.clear();
      chats.clear();
      recent.clear();
    }

    searchStatus.value = RxStatus.loading();

    populate();
  });

  _ensureScrollable();
  populate();

  super.onInit();
}