2023-08-06 19:46:40 -04:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
|
|
|
import 'package:flutter_translate/flutter_translate.dart';
|
2023-09-26 18:46:02 -04:00
|
|
|
import '../proto/proto.dart' as proto;
|
2023-08-06 19:46:40 -04:00
|
|
|
import '../providers/account.dart';
|
|
|
|
import '../providers/chat.dart';
|
|
|
|
import '../tools/theme_service.dart';
|
|
|
|
|
|
|
|
class ChatSingleContactItemWidget extends ConsumerWidget {
|
|
|
|
const ChatSingleContactItemWidget({required this.contact, super.key});
|
|
|
|
|
|
|
|
final proto.Contact contact;
|
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: prefer_expression_function_bodies
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
final theme = Theme.of(context);
|
2023-09-25 22:59:28 -04:00
|
|
|
//final textTheme = theme.textTheme;
|
2023-08-06 19:46:40 -04:00
|
|
|
final scale = theme.extension<ScaleScheme>()!;
|
|
|
|
|
2023-09-30 21:00:22 -04:00
|
|
|
final activeChat = ref.watch(activeChatStateProvider);
|
2023-08-07 11:02:29 -04:00
|
|
|
final remoteConversationRecordKey =
|
|
|
|
proto.TypedKeyProto.fromProto(contact.remoteConversationRecordKey);
|
|
|
|
final selected = activeChat == remoteConversationRecordKey;
|
2023-08-06 19:46:40 -04:00
|
|
|
|
|
|
|
return Container(
|
2023-09-24 15:30:54 -04:00
|
|
|
margin: const EdgeInsets.fromLTRB(0, 4, 0, 0),
|
2023-08-06 19:46:40 -04:00
|
|
|
clipBehavior: Clip.antiAlias,
|
|
|
|
decoration: ShapeDecoration(
|
2023-09-24 15:30:54 -04:00
|
|
|
color: scale.tertiaryScale.subtleBorder,
|
2023-08-06 19:46:40 -04:00
|
|
|
shape: RoundedRectangleBorder(
|
2023-09-24 15:30:54 -04:00
|
|
|
borderRadius: BorderRadius.circular(8),
|
2023-08-06 19:46:40 -04:00
|
|
|
)),
|
|
|
|
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 deleteChat(
|
|
|
|
activeAccountInfo: activeAccountInfo,
|
|
|
|
remoteConversationRecordKey:
|
2023-08-07 11:02:29 -04:00
|
|
|
remoteConversationRecordKey);
|
2023-08-06 19:46:40 -04:00
|
|
|
ref.invalidate(fetchChatListProvider);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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',
|
|
|
|
// ),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
|
|
|
|
// The child of the Slidable is what the user sees when the
|
|
|
|
// component is not dragged.
|
|
|
|
child: ListTile(
|
|
|
|
onTap: () async {
|
2023-09-30 21:00:22 -04:00
|
|
|
ref.read(activeChatStateProvider.notifier).state =
|
|
|
|
remoteConversationRecordKey;
|
2023-08-06 19:46:40 -04:00
|
|
|
ref.invalidate(fetchChatListProvider);
|
|
|
|
},
|
|
|
|
title: Text(contact.editedProfile.name),
|
|
|
|
|
|
|
|
/// xxx show last message here
|
2023-09-28 10:06:22 -04:00
|
|
|
subtitle: (contact.editedProfile.pronouns.isNotEmpty)
|
|
|
|
? Text(contact.editedProfile.pronouns)
|
2023-08-06 19:46:40 -04:00
|
|
|
: null,
|
|
|
|
iconColor: scale.tertiaryScale.background,
|
|
|
|
textColor: scale.tertiaryScale.text,
|
|
|
|
selected: selected,
|
|
|
|
//Text(Timestamp.fromInt64(contactInvitationRecord.expiration) / ),
|
|
|
|
leading: const Icon(Icons.chat))));
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
|
|
super.debugFillProperties(properties);
|
|
|
|
properties.add(DiagnosticsProperty<proto.Contact>('contact', contact));
|
|
|
|
}
|
|
|
|
}
|