veilidchat/lib/contacts/views/contact_list_widget.dart

87 lines
3.4 KiB
Dart
Raw Normal View History

2023-08-05 01:00:46 -04:00
import 'package:awesome_extensions/awesome_extensions.dart';
2023-08-04 01:00:38 -04:00
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
2023-08-06 19:46:40 -04:00
import 'package:flutter/foundation.dart';
2023-07-28 20:36:05 -04:00
import 'package:flutter/material.dart';
2023-08-04 01:00:38 -04:00
import 'package:flutter_translate/flutter_translate.dart';
import 'package:searchable_listview/searchable_listview.dart';
2023-07-28 20:36:05 -04:00
2024-01-30 17:03:14 -05:00
import '../../proto/proto.dart' as proto;
import '../../theme/theme.dart';
2023-08-04 01:00:38 -04:00
import 'contact_item_widget.dart';
2023-07-29 10:55:35 -04:00
import 'empty_contact_list_widget.dart';
2024-07-08 21:29:52 -04:00
class ContactListWidget extends StatefulWidget {
2024-02-27 12:45:58 -05:00
const ContactListWidget(
{required this.contactList, required this.disabled, super.key});
2024-07-24 15:20:29 -04:00
final IList<proto.Contact>? contactList;
2024-02-27 12:45:58 -05:00
final bool disabled;
2023-07-28 20:36:05 -04:00
2024-07-08 21:29:52 -04:00
@override
State<ContactListWidget> createState() => _ContactListWidgetState();
2023-08-06 19:46:40 -04:00
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
2024-02-27 12:45:58 -05:00
properties
..add(IterableProperty<proto.Contact>('contactList', contactList))
..add(DiagnosticsProperty<bool>('disabled', disabled));
2023-08-06 19:46:40 -04:00
}
2024-07-08 21:29:52 -04:00
}
2024-07-11 23:04:08 -04:00
class _ContactListWidgetState extends State<ContactListWidget>
with SingleTickerProviderStateMixin {
2023-07-28 20:36:05 -04:00
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
2024-07-11 23:04:08 -04:00
//final textTheme = theme.textTheme;
final scale = theme.extension<ScaleScheme>()!;
2024-07-11 23:04:08 -04:00
final scaleConfig = theme.extension<ScaleConfig>()!;
2024-07-11 23:04:08 -04:00
return SliverLayoutBuilder(
builder: (context, constraints) => styledHeaderSliver(
context: context,
backgroundColor: scaleConfig.preferBorders
? scale.primaryScale.subtleBackground
: scale.primaryScale.subtleBorder,
title: translate('contacts_page.contacts'),
sliver: SliverFillRemaining(
child: SearchableList<proto.Contact>.sliver(
2024-07-24 15:20:29 -04:00
initialList: widget.contactList == null
? []
: widget.contactList!.toList(),
2024-07-11 23:04:08 -04:00
itemBuilder: (c) =>
ContactItemWidget(contact: c, disabled: widget.disabled)
.paddingLTRB(0, 4, 0, 0),
filter: (value) {
final lowerValue = value.toLowerCase();
2024-07-24 15:20:29 -04:00
if (widget.contactList == null) {
return [];
}
return widget.contactList!
2024-07-11 23:04:08 -04:00
.where((element) =>
element.nickname.toLowerCase().contains(lowerValue) ||
element.profile.name
.toLowerCase()
.contains(lowerValue) ||
element.profile.pronouns
.toLowerCase()
.contains(lowerValue))
.toList();
},
searchFieldHeight: 40,
spaceBetweenSearchAndList: 4,
2024-07-24 15:20:29 -04:00
emptyWidget: widget.contactList == null
? waitingPage(
text: translate('contacts_page.loading_contacts'))
: const EmptyContactListWidget(),
2024-07-11 23:04:08 -04:00
defaultSuffixIconColor: scale.primaryScale.border,
closeKeyboardWhenScrolling: true,
2024-07-24 15:20:29 -04:00
searchFieldEnabled: widget.contactList != null,
2024-07-11 23:04:08 -04:00
inputDecoration: InputDecoration(
labelText: translate('contact_list.search'),
),
),
)));
}
2023-07-28 20:36:05 -04:00
}