veilidchat/lib/contacts/views/contact_list_widget.dart

77 lines
2.5 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});
2023-08-04 01:00:38 -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
}
class _ContactListWidgetState extends State<ContactListWidget> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
2023-08-06 19:46:40 -04:00
2023-07-28 20:36:05 -04:00
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scale = theme.extension<ScaleScheme>()!;
2024-07-08 21:29:52 -04:00
return styledTitleContainer(
context: context,
title: translate('contact_list.title'),
child: SearchableList<proto.Contact>(
shrinkWrap: true,
initialList: widget.contactList.toList(),
itemBuilder: (c) =>
ContactItemWidget(contact: c, disabled: widget.disabled)
.paddingLTRB(0, 4, 0, 0),
filter: (value) {
final lowerValue = value.toLowerCase();
return widget.contactList
.where((element) =>
element.nickname.toLowerCase().contains(lowerValue) ||
element.profile.name.toLowerCase().contains(lowerValue) ||
element.profile.pronouns.toLowerCase().contains(lowerValue))
.toList();
},
searchFieldHeight: 40,
spaceBetweenSearchAndList: 4,
emptyWidget: const EmptyContactListWidget(),
defaultSuffixIconColor: scale.primaryScale.border,
closeKeyboardWhenScrolling: true,
inputDecoration: InputDecoration(
labelText: translate('contact_list.search'),
),
).paddingAll(8),
).paddingLTRB(8, 0, 8, 8);
}
2023-07-28 20:36:05 -04:00
}