widgetChatList function

ChatWidgetBundle widgetChatList(
  1. BuildContext context,
  2. dynamic service, {
  3. required dynamic onPressed(
    1. Chat chat
    ),
  4. List<Chat>? cachedChatList,
  5. dynamic onChatUpdated(
    1. List<Chat> updatedChat
    )?,
})

Implementation

ChatWidgetBundle widgetChatList(
  BuildContext context,
  service, {
  required Function(Chat chat) onPressed,
  List<Chat>? cachedChatList,
  Function(List<Chat> updatedChat)? onChatUpdated,
}) {
  final controller = Get.put(
    SourceChatlistController(
      service: service,
      cachedChatList: cachedChatList,
      onChatUpdated: onChatUpdated,
    ),
  );
  Widget widget = Obx(
    () => controller.filteredchatList.value == null
        ? const Center(
            child: CupertinoActivityIndicator(),
          )
        : Column(
            children: List.generate(
              controller.filteredchatList.value!.length,
              (index) {
                return Obx(
                  () => ChatWidgetv2.listtilechat(
                    context,
                    chat: controller.filteredchatList.value![index],
                    onPressed: onPressed,
                    onDelete: () {
                      controller.filteredchatList.value!.removeWhere(
                        (element) =>
                            element.user.userID ==
                            controller
                                .filteredchatList.value![index].user.userID,
                      );
                      controller.filteredchatList.refresh();
                    },
                  ),
                );
              },
            ),
          ),
  );

  return ChatWidgetBundle(
    widget: Rxn(widget),
    refresh: () async => await controller.refreshAllChatList(),
    loadMore: () async => await controller.loadMoreChatList(),
    filterList: (String text) => controller.filterList(text),
  );
}