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';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.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
|
|
|
|
2023-09-26 18:46:02 -04:00
|
|
|
import '../proto/proto.dart' as proto;
|
2023-08-04 01:00:38 -04:00
|
|
|
import '../tools/tools.dart';
|
|
|
|
import 'contact_item_widget.dart';
|
2023-07-29 10:55:35 -04:00
|
|
|
import 'empty_contact_list_widget.dart';
|
|
|
|
|
|
|
|
class ContactListWidget extends ConsumerWidget {
|
|
|
|
const ContactListWidget({required this.contactList, super.key});
|
2023-08-04 01:00:38 -04:00
|
|
|
final IList<proto.Contact> contactList;
|
2023-07-28 20:36:05 -04:00
|
|
|
|
2023-08-06 19:46:40 -04:00
|
|
|
@override
|
|
|
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
|
|
super.debugFillProperties(properties);
|
|
|
|
properties.add(IterableProperty<proto.Contact>('contactList', contactList));
|
|
|
|
}
|
|
|
|
|
2023-07-28 20:36:05 -04:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-09-24 15:30:54 -04:00
|
|
|
final theme = Theme.of(context);
|
|
|
|
//final textTheme = theme.textTheme;
|
|
|
|
final scale = theme.extension<ScaleScheme>()!;
|
|
|
|
|
2023-09-23 22:19:53 -04:00
|
|
|
return SizedBox.expand(
|
|
|
|
child: styledTitleContainer(
|
|
|
|
context: context,
|
|
|
|
title: translate('contact_list.title'),
|
|
|
|
child: SizedBox.expand(
|
|
|
|
child: (contactList.isEmpty)
|
|
|
|
? const EmptyContactListWidget()
|
|
|
|
: SearchableList<proto.Contact>(
|
|
|
|
autoFocusOnSearch: false,
|
|
|
|
initialList: contactList.toList(),
|
|
|
|
builder: (l, i, c) => ContactItemWidget(contact: c),
|
|
|
|
filter: (value) {
|
|
|
|
final lowerValue = value.toLowerCase();
|
|
|
|
return contactList
|
|
|
|
.where((element) =>
|
|
|
|
element.editedProfile.name
|
|
|
|
.toLowerCase()
|
|
|
|
.contains(lowerValue) ||
|
|
|
|
element.editedProfile.title
|
|
|
|
.toLowerCase()
|
|
|
|
.contains(lowerValue))
|
|
|
|
.toList();
|
|
|
|
},
|
2023-09-24 15:30:54 -04:00
|
|
|
spaceBetweenSearchAndList: 4,
|
2023-09-23 22:19:53 -04:00
|
|
|
inputDecoration: InputDecoration(
|
|
|
|
labelText: translate('contact_list.search'),
|
2023-09-24 15:30:54 -04:00
|
|
|
contentPadding: const EdgeInsets.all(2),
|
|
|
|
fillColor: scale.primaryScale.text,
|
2023-09-23 22:19:53 -04:00
|
|
|
focusedBorder: OutlineInputBorder(
|
2023-09-24 15:30:54 -04:00
|
|
|
borderSide: BorderSide(
|
|
|
|
color: scale.primaryScale.hoverBorder,
|
2023-09-23 22:19:53 -04:00
|
|
|
),
|
2023-09-24 15:30:54 -04:00
|
|
|
borderRadius: BorderRadius.circular(8),
|
2023-09-23 22:19:53 -04:00
|
|
|
),
|
2023-08-05 01:00:46 -04:00
|
|
|
),
|
2023-09-24 15:30:54 -04:00
|
|
|
).paddingAll(8),
|
2023-09-23 22:19:53 -04:00
|
|
|
))).paddingLTRB(8, 0, 8, 8);
|
2023-07-28 20:36:05 -04:00
|
|
|
}
|
|
|
|
}
|