Files
tatuchat/lib/pages/chat_list/tabs/channels_tab.dart
Welton Moura 0037b0b9cf
Some checks failed
Main Deploy Workflow / deploy_web (push) Has been cancelled
Main Deploy Workflow / deploy_playstore_internal (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
Initial commit
2026-09-11 15:59:56 -03:00

79 lines
2.6 KiB
Dart

// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:material_ui/material_ui.dart';
import 'package:matrix/matrix.dart';
import 'package:tatchat/l10n/l10n.dart';
import 'package:tatchat/pages/chat_list/chat_list.dart';
import 'package:tatchat/pages/chat_list/chat_list_item.dart';
import 'package:tatchat/pages/chat_list/tabs/empty_tab_view.dart';
import 'package:tatchat/utils/stream_extension.dart';
import 'package:tatchat/widgets/matrix.dart';
class ChannelsTab extends StatelessWidget {
final ChatListController controller;
const ChannelsTab(this.controller, {super.key});
@override
Widget build(BuildContext context) {
final client = Matrix.of(context).client;
final theme = Theme.of(context);
return StreamBuilder(
key: ValueKey(client.userID.toString()),
stream: client.onSync.stream
.where((s) => s.hasRoomUpdate)
.rateLimit(const Duration(seconds: 1)),
builder: (context, _) {
final channels = client.rooms
.where((room) => !room.isSpace && !room.isDirectChat)
.toList();
return CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
Icon(
Icons.tag_outlined,
color: theme.colorScheme.primary,
),
const SizedBox(width: 8),
Text(
L10n.of(context).channels,
style: theme.textTheme.titleLarge,
),
],
),
),
),
if (channels.isEmpty)
SliverFillRemaining(
hasScrollBody: false,
child: EmptyTabView(
icon: Icons.tag_outlined,
title: L10n.of(context).noChannelsFound,
),
)
else
SliverList.builder(
itemCount: channels.length,
itemBuilder: (context, i) {
final room = channels[i];
return ChatListItem(
room,
key: Key('channel_list_item_${room.id}'),
onTap: () => controller.onChatTap(room),
activeChat: controller.activeChat == room.id,
);
},
),
],
);
},
);
}
}