2021-11-14 18:47:18 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2021-11-15 07:24:05 +01:00
|
|
|
import 'package:salomon_bottom_bar/salomon_bottom_bar.dart';
|
2021-11-14 18:47:18 +01:00
|
|
|
|
|
|
|
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
2022-04-03 19:00:35 +02:00
|
|
|
import 'package:fluffychat/pages/chat_list/spaces_entry.dart';
|
2021-11-14 18:47:18 +01:00
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
2021-11-15 10:05:15 +01:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-11-14 18:47:18 +01:00
|
|
|
|
|
|
|
class SpacesBottomBar extends StatelessWidget {
|
|
|
|
final ChatListController controller;
|
2022-01-29 12:35:03 +01:00
|
|
|
const SpacesBottomBar(this.controller, {Key? key}) : super(key: key);
|
2021-11-14 18:47:18 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-04-03 19:00:35 +02:00
|
|
|
final foundIndex = controller.spacesEntries.indexWhere(
|
|
|
|
(se) => spacesEntryRoughEquivalence(se, controller.activeSpacesEntry));
|
|
|
|
final currentIndex = foundIndex == -1 ? 0 : foundIndex;
|
2021-11-15 07:24:05 +01:00
|
|
|
return Material(
|
|
|
|
color: Theme.of(context).appBarTheme.backgroundColor,
|
|
|
|
elevation: 6,
|
2021-11-23 11:37:25 +01:00
|
|
|
child: SafeArea(
|
|
|
|
child: StreamBuilder<Object>(
|
|
|
|
stream: Matrix.of(context).client.onSync.stream.where((sync) =>
|
2022-01-29 12:35:03 +01:00
|
|
|
(sync.rooms?.join?.values.any((r) =>
|
|
|
|
r.state?.any((s) => s.type.startsWith('m.space')) ??
|
|
|
|
false) ??
|
2021-11-23 11:37:25 +01:00
|
|
|
false) ||
|
|
|
|
(sync.rooms?.leave?.isNotEmpty ?? false)),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return Container(
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: SalomonBottomBar(
|
|
|
|
itemPadding: const EdgeInsets.all(8),
|
|
|
|
currentIndex: currentIndex,
|
2022-04-03 19:00:35 +02:00
|
|
|
onTap: (i) => controller.setActiveSpacesEntry(
|
2021-11-23 11:37:25 +01:00
|
|
|
context,
|
2022-04-03 19:00:35 +02:00
|
|
|
controller.spacesEntries[i],
|
2021-11-15 10:09:23 +01:00
|
|
|
),
|
2021-11-23 11:37:25 +01:00
|
|
|
selectedItemColor: Theme.of(context).colorScheme.primary,
|
2022-04-03 19:00:35 +02:00
|
|
|
items: controller.spacesEntries
|
|
|
|
.map((entry) => _buildSpacesEntryUI(context, entry))
|
|
|
|
.toList(),
|
2021-11-23 11:37:25 +01:00
|
|
|
),
|
2021-11-15 10:05:15 +01:00
|
|
|
),
|
2021-11-23 11:37:25 +01:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
2021-11-14 18:47:18 +01:00
|
|
|
);
|
|
|
|
}
|
2022-04-03 19:00:35 +02:00
|
|
|
|
|
|
|
SalomonBottomBarItem _buildSpacesEntryUI(
|
|
|
|
BuildContext context, SpacesEntry entry) {
|
|
|
|
final space = entry.getSpace(context);
|
|
|
|
if (space != null) {
|
|
|
|
return SalomonBottomBarItem(
|
|
|
|
icon: InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(28),
|
|
|
|
onTap: () => controller.setActiveSpacesEntry(
|
|
|
|
context,
|
|
|
|
entry,
|
|
|
|
),
|
|
|
|
onLongPress: () => controller.editSpace(context, space.id),
|
|
|
|
child: Avatar(
|
|
|
|
mxContent: space.avatar,
|
|
|
|
name: space.displayname,
|
|
|
|
size: 24,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
title: Text(entry.getName(context)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return SalomonBottomBarItem(
|
|
|
|
icon: entry.getIcon(false),
|
|
|
|
activeIcon: entry.getIcon(true),
|
|
|
|
title: Text(entry.getName(context)),
|
|
|
|
);
|
|
|
|
}
|
2021-11-14 18:47:18 +01:00
|
|
|
}
|