fluffychat/lib/pages/chat_list/chat_list_header.dart

136 lines
5.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2023-03-19 18:59:50 +00:00
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat_list/chat_list.dart';
import 'package:fluffychat/pages/chat_list/client_chooser_button.dart';
2022-08-30 18:24:36 +00:00
import '../../widgets/matrix.dart';
class ChatListHeader extends StatelessWidget implements PreferredSizeWidget {
final ChatListController controller;
2024-03-10 15:26:40 +00:00
final bool globalSearch;
2024-03-10 15:26:40 +00:00
const ChatListHeader({
super.key,
required this.controller,
this.globalSearch = true,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final selectMode = controller.selectMode;
2023-03-19 18:59:50 +00:00
return SliverAppBar(
floating: true,
2023-12-22 19:18:51 +00:00
toolbarHeight: 72,
pinned:
FluffyThemes.isColumnMode(context) || selectMode != SelectMode.normal,
scrolledUnderElevation: selectMode == SelectMode.normal ? 0 : null,
backgroundColor:
selectMode == SelectMode.normal ? Colors.transparent : null,
2022-07-07 16:50:13 +00:00
automaticallyImplyLeading: false,
leading: selectMode == SelectMode.normal
? null
: IconButton(
tooltip: L10n.of(context)!.cancel,
icon: const Icon(Icons.close_outlined),
onPressed: controller.cancelAction,
color: theme.colorScheme.primary,
2022-07-07 16:50:13 +00:00
),
title: selectMode == SelectMode.share
? Text(
L10n.of(context)!.share,
key: const ValueKey(SelectMode.share),
)
2024-07-14 14:49:46 +00:00
: TextField(
controller: controller.searchController,
focusNode: controller.searchFocusNode,
textInputAction: TextInputAction.search,
onChanged: (text) => controller.onSearchEnter(
text,
globalSearch: globalSearch,
),
decoration: InputDecoration(
2024-08-17 10:16:55 +00:00
filled: true,
fillColor: theme.colorScheme.secondaryContainer,
2024-07-14 14:49:46 +00:00
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(99),
),
contentPadding: EdgeInsets.zero,
hintText: L10n.of(context)!.searchChatsRooms,
hintStyle: TextStyle(
color: theme.colorScheme.onPrimaryContainer,
2024-07-14 14:49:46 +00:00
fontWeight: FontWeight.normal,
),
floatingLabelBehavior: FloatingLabelBehavior.never,
prefixIcon: controller.isSearchMode
? IconButton(
tooltip: L10n.of(context)!.cancel,
icon: const Icon(Icons.close_outlined),
onPressed: controller.cancelSearch,
color: theme.colorScheme.onPrimaryContainer,
2024-07-14 14:49:46 +00:00
)
: IconButton(
onPressed: controller.startSearch,
icon: Icon(
Icons.search_outlined,
color: theme.colorScheme.onPrimaryContainer,
2024-07-14 14:49:46 +00:00
),
),
suffixIcon: controller.isSearchMode && globalSearch
? controller.isSearching
? const Padding(
padding: EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 12,
),
child: SizedBox.square(
dimension: 24,
child: CircularProgressIndicator.adaptive(
strokeWidth: 2,
),
),
2023-07-22 09:11:35 +00:00
)
2024-07-14 14:49:46 +00:00
: TextButton.icon(
onPressed: controller.setServer,
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(99),
),
textStyle: const TextStyle(fontSize: 12),
2023-08-13 09:15:13 +00:00
),
2024-07-14 14:49:46 +00:00
icon: const Icon(Icons.edit_outlined, size: 16),
label: Text(
controller.searchServer ??
Matrix.of(context).client.homeserver!.host,
maxLines: 2,
),
)
: SizedBox(
width: 0,
child: ClientChooserButton(controller),
),
),
),
actions: selectMode == SelectMode.share
2022-09-10 09:53:39 +00:00
? [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
child: ClientChooserButton(controller),
),
]
2024-07-14 14:49:46 +00:00
: null,
);
}
@override
Size get preferredSize => const Size.fromHeight(56);
}