renderRemoteSubspaces function

dynamic renderRemoteSubspaces(
  1. dynamic context,
  2. dynamic ref,
  3. String spaceIdOrAlias,
  4. List spaces, {
  5. int? maxLength,
  6. dynamic padding,
})

Implementation

Widget renderRemoteSubspaces(
  BuildContext context,
  WidgetRef ref,
  String spaceIdOrAlias,
  List<SpaceHierarchyRoomInfo> spaces, {
  int? maxLength,
  EdgeInsetsGeometry? padding,
}) {
  if (spaces.isEmpty) {
    return const SizedBox.shrink();
  }

  int itemCount = spaces.length;
  if (maxLength != null && maxLength < itemCount) {
    itemCount = maxLength;
  }

  return GridView.builder(
    padding: padding,
    itemCount: itemCount,
    physics: const NeverScrollableScrollPhysics(),
    gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
      crossAxisCount: 1,
      childAspectRatio: 4.0,
      mainAxisExtent: 100,
    ),
    shrinkWrap: true,
    itemBuilder: (context, index) {
      final roomInfo = spaces[index];
      final parentId = spaceIdOrAlias;
      final roomId = roomInfo.roomIdStr();
      return RoomHierarchyCard(
        key: Key('subspace-list-item-$roomId'),
        roomInfo: roomInfo,
        parentId: parentId,
        indicateIfSuggested: true,
        trailing: Wrap(
          children: [
            RoomHierarchyJoinButton(
              joinRule: roomInfo.joinRuleStr().toLowerCase(),
              roomId: roomId,
              roomName: roomInfo.name() ?? roomId,
              viaServerName: roomInfo.viaServerName(),
              forward: (spaceId) {
                goToSpace(context, spaceId);
                ref.invalidate(spaceRelationsProvider(parentId));
                ref.invalidate(spaceRemoteRelationsProvider(parentId));
              },
            ),
            RoomHierarchyOptionsMenu(
              isSuggested: roomInfo.suggested(),
              childId: roomId,
              parentId: parentId,
            ),
          ],
        ),
      );
    },
  );
}