renderRemoteChats function

dynamic renderRemoteChats(
  1. dynamic context,
  2. dynamic ref,
  3. String parentId,
  4. List chats,
  5. int? maxItems, {
  6. bool showSuggestedMarkIfGiven = true,
  7. bool renderMenu = true,
})

Implementation

Widget renderRemoteChats(
  BuildContext context,
  WidgetRef ref,
  String parentId,
  List<SpaceHierarchyRoomInfo> chats,
  int? maxItems, {
  bool showSuggestedMarkIfGiven = true,
  bool renderMenu = true,
}) {
  if (chats.isEmpty) return const SizedBox.shrink();
  return ListView.builder(
    shrinkWrap: true,
    padding: EdgeInsets.zero,
    physics: const NeverScrollableScrollPhysics(),
    itemCount: maxItems ?? chats.length,
    itemBuilder: (context, index) {
      final roomInfo = chats[index];
      final roomId = roomInfo.roomIdStr();
      return RoomHierarchyCard(
        indicateIfSuggested: showSuggestedMarkIfGiven,
        parentId: parentId,
        roomInfo: roomInfo,
        trailing: Wrap(
          children: [
            RoomHierarchyJoinButton(
              joinRule: roomInfo.joinRuleStr().toLowerCase(),
              roomId: roomId,
              roomName: roomInfo.name() ?? roomId,
              viaServerName: roomInfo.viaServerName(),
              forward: (roomId) {
                goToChat(context, roomId);
                // make sure the UI refreshes when the user comes back here
                ref.invalidate(spaceRelationsProvider(parentId));
                ref.invalidate(spaceRemoteRelationsProvider(parentId));
              },
            ),
            if (renderMenu)
              RoomHierarchyOptionsMenu(
                isSuggested: roomInfo.suggested(),
                childId: roomId,
                parentId: parentId,
              ),
          ],
        ),
      );
    },
  );
}