alterações em telas
This commit is contained in:
@@ -4,43 +4,105 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:tatchat/config/app_config.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/chat_tab_header.dart';
|
||||
import 'package:tatchat/pages/chat_list/tabs/empty_tab_view.dart';
|
||||
import 'package:tatchat/pages/chat_list/tabs/home_tab.dart';
|
||||
import 'package:tatchat/utils/matrix_sdk_extensions/matrix_locals.dart';
|
||||
import 'package:tatchat/utils/stream_extension.dart';
|
||||
import 'package:tatchat/widgets/matrix.dart';
|
||||
|
||||
class MuralsTab extends StatelessWidget {
|
||||
const MuralsTab({super.key});
|
||||
class MuralsTab extends StatefulWidget {
|
||||
final ChatListController controller;
|
||||
|
||||
const MuralsTab(this.controller, {super.key});
|
||||
|
||||
@override
|
||||
State<MuralsTab> createState() => _MuralsTabState();
|
||||
}
|
||||
|
||||
class _MuralsTabState extends State<MuralsTab> {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocusNode = FocusNode();
|
||||
bool _isSearchMode = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
_searchFocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = L10n.of(context);
|
||||
return ColoredBox(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.dashboard_outlined,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
final client = Matrix.of(context).client;
|
||||
final theme = Theme.of(context);
|
||||
final searchText = _searchController.text.trim().toLowerCase();
|
||||
return ChatTabScaffold(
|
||||
tab: HomeTab.murals,
|
||||
isSearchMode: _isSearchMode,
|
||||
onSearchPressed: () => setState(() => _isSearchMode = true),
|
||||
onSearchCancelled: () {
|
||||
setState(() {
|
||||
_isSearchMode = false;
|
||||
_searchController.clear();
|
||||
});
|
||||
},
|
||||
searchController: _searchController,
|
||||
searchFocusNode: _searchFocusNode,
|
||||
onSearchChanged: (_) => setState(() {}),
|
||||
controller: widget.controller,
|
||||
child: StreamBuilder(
|
||||
key: ValueKey(client.userID.toString()),
|
||||
stream: client.onSync.stream
|
||||
.where((s) => s.hasRoomUpdate)
|
||||
.rateLimit(const Duration(seconds: 1)),
|
||||
builder: (context, _) {
|
||||
final murals = client.rooms
|
||||
.where((room) => room.tags.keys.contains(AppConfig.muralTag))
|
||||
.where(
|
||||
(room) =>
|
||||
searchText.isEmpty ||
|
||||
room
|
||||
.getLocalizedDisplayname(MatrixLocals(L10n.of(context)))
|
||||
.toLowerCase()
|
||||
.contains(searchText),
|
||||
)
|
||||
.toList();
|
||||
return ColoredBox(
|
||||
color: theme.colorScheme.surface,
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
if (murals.isEmpty)
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: EmptyTabView(
|
||||
icon: Icons.dashboard_outlined,
|
||||
title: L10n.of(context).noMuralsFound,
|
||||
),
|
||||
)
|
||||
else
|
||||
SliverList.builder(
|
||||
itemCount: murals.length,
|
||||
itemBuilder: (context, i) {
|
||||
final room = murals[i];
|
||||
return ChatListItem(
|
||||
room,
|
||||
key: Key('mural_list_item_${room.id}'),
|
||||
onTap: () => widget.controller.onChatTap(room),
|
||||
activeChat: widget.controller.activeChat == room.id,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(l10n.murals, style: Theme.of(context).textTheme.titleLarge),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: EmptyTabView(
|
||||
icon: Icons.dashboard_outlined,
|
||||
title: l10n.muralsComingSoon,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user