veilidchat/lib/components/contact_item_widget.dart

121 lines
5.0 KiB
Dart
Raw Normal View History

2023-08-05 23:58:13 -04:00
import 'package:flutter/foundation.dart';
2023-08-04 01:00:38 -04:00
import 'package:flutter/material.dart';
2023-08-07 00:55:57 -04:00
import 'package:flutter_animate/flutter_animate.dart';
2023-08-04 01:00:38 -04:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
2023-08-05 23:58:13 -04:00
import 'package:flutter_translate/flutter_translate.dart';
2023-08-04 01:00:38 -04:00
import '../../entities/proto.dart' as proto;
2023-08-07 00:55:57 -04:00
import '../pages/main_pager/main_pager.dart';
2023-08-05 23:58:13 -04:00
import '../providers/account.dart';
2023-08-06 19:46:40 -04:00
import '../providers/chat.dart';
2023-08-05 23:58:13 -04:00
import '../providers/contact.dart';
import '../tools/theme_service.dart';
2023-08-04 01:00:38 -04:00
class ContactItemWidget extends ConsumerWidget {
const ContactItemWidget({required this.contact, super.key});
final proto.Contact contact;
@override
// ignore: prefer_expression_function_bodies
Widget build(BuildContext context, WidgetRef ref) {
2023-08-05 23:58:13 -04:00
final theme = Theme.of(context);
final textTheme = theme.textTheme;
final scale = theme.extension<ScaleScheme>()!;
2023-08-04 01:00:38 -04:00
2023-08-07 00:55:57 -04:00
final remoteConversationKey =
2023-08-07 11:02:29 -04:00
proto.TypedKeyProto.fromProto(contact.remoteConversationRecordKey);
2023-08-07 00:55:57 -04:00
2023-08-05 23:58:13 -04:00
return Container(
margin: const EdgeInsets.fromLTRB(4, 4, 4, 0),
clipBehavior: Clip.antiAlias,
decoration: ShapeDecoration(
color: scale.tertiaryScale.subtleBackground,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
)),
child: Slidable(
key: ObjectKey(contact),
endActionPane: ActionPane(
motion: const DrawerMotion(),
children: [
SlidableAction(
onPressed: (context) async {
final activeAccountInfo =
await ref.read(fetchActiveAccountProvider.future);
if (activeAccountInfo != null) {
await deleteContact(
activeAccountInfo: activeAccountInfo,
contact: contact);
2023-08-06 19:46:40 -04:00
ref
..invalidate(fetchContactListProvider)
..invalidate(fetchChatListProvider);
2023-08-05 23:58:13 -04:00
}
},
backgroundColor: scale.tertiaryScale.background,
foregroundColor: scale.tertiaryScale.text,
icon: Icons.delete,
label: translate('button.delete'),
padding: const EdgeInsets.all(2)),
// SlidableAction(
// onPressed: (context) => (),
// backgroundColor: scale.secondaryScale.background,
// foregroundColor: scale.secondaryScale.text,
// icon: Icons.edit,
// label: 'Edit',
// ),
],
2023-08-04 01:00:38 -04:00
),
2023-08-05 23:58:13 -04:00
// The child of the Slidable is what the user sees when the
// component is not dragged.
child: ListTile(
onTap: () async {
2023-08-07 00:55:57 -04:00
final activeAccountInfo =
await ref.read(fetchActiveAccountProvider.future);
if (activeAccountInfo != null) {
// Start a chat
await getOrCreateChatSingleContact(
activeAccountInfo: activeAccountInfo,
remoteConversationRecordKey: remoteConversationKey);
// Click over to chats
2023-08-07 11:02:29 -04:00
if (context.mounted) {
await MainPager.of(context)?.pageController.animateToPage(
1,
duration: 250.ms,
curve: Curves.easeInOut);
}
2023-08-07 00:55:57 -04:00
}
2023-08-05 23:58:13 -04:00
// // ignore: use_build_context_synchronously
// if (!context.mounted) {
// return;
// }
// await showDialog<void>(
// context: context,
// builder: (context) => ContactInvitationDisplayDialog(
// name: activeAccountInfo.localAccount.name,
// message: contactInvitationRecord.message,
// generator: Uint8List.fromList(
// contactInvitationRecord.invitation),
// ));
// }
},
title: Text(contact.editedProfile.name),
subtitle: (contact.editedProfile.title.isNotEmpty)
? Text(contact.editedProfile.title)
: null,
iconColor: scale.tertiaryScale.background,
textColor: scale.tertiaryScale.text,
//Text(Timestamp.fromInt64(contactInvitationRecord.expiration) / ),
leading: const Icon(Icons.person))));
}
2023-08-04 01:00:38 -04:00
2023-08-05 23:58:13 -04:00
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<proto.Contact>('contact', contact));
2023-08-04 01:00:38 -04:00
}
}