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';
|
2024-01-30 17:03:14 -05:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2023-08-05 23:58:13 -04:00
|
|
|
import 'package:flutter_translate/flutter_translate.dart';
|
2024-01-30 17:03:14 -05:00
|
|
|
import '../../chat_list/chat_list.dart';
|
2024-01-30 19:47:22 -05:00
|
|
|
import '../../layout/layout.dart';
|
2024-01-09 20:58:27 -05:00
|
|
|
import '../../proto/proto.dart' as proto;
|
|
|
|
import '../../theme/theme.dart';
|
2024-01-30 17:03:14 -05:00
|
|
|
import '../contacts.dart';
|
2023-08-04 01:00:38 -04:00
|
|
|
|
2024-01-09 20:58:27 -05:00
|
|
|
class ContactItemWidget extends StatelessWidget {
|
2024-02-27 12:45:58 -05:00
|
|
|
const ContactItemWidget(
|
|
|
|
{required this.contact, required this.disabled, super.key});
|
2023-08-04 01:00:38 -04:00
|
|
|
|
|
|
|
final proto.Contact contact;
|
2024-02-27 12:45:58 -05:00
|
|
|
final bool disabled;
|
2023-08-04 01:00:38 -04:00
|
|
|
|
2024-04-12 20:55:05 -04:00
|
|
|
@override
|
|
|
|
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
|
|
|
super.debugFillProperties(properties);
|
|
|
|
properties
|
|
|
|
..add(DiagnosticsProperty<proto.Contact>('contact', contact))
|
|
|
|
..add(DiagnosticsProperty<bool>('disabled', disabled));
|
|
|
|
}
|
|
|
|
|
2023-08-04 01:00:38 -04:00
|
|
|
@override
|
|
|
|
// ignore: prefer_expression_function_bodies
|
2024-01-09 20:58:27 -05:00
|
|
|
Widget build(
|
|
|
|
BuildContext context,
|
|
|
|
) {
|
2024-05-27 18:04:00 -04:00
|
|
|
final localConversationRecordKey =
|
|
|
|
contact.localConversationRecordKey.toVeilid();
|
2023-08-07 00:55:57 -04:00
|
|
|
|
2024-04-10 16:13:08 -04:00
|
|
|
const selected = false; // xxx: eventually when we have selectable contacts:
|
2024-05-27 18:04:00 -04:00
|
|
|
// activeContactCubit.state == localConversationRecordKey;
|
2024-04-07 23:16:06 -04:00
|
|
|
|
2024-04-12 20:55:05 -04:00
|
|
|
final tileDisabled = disabled || context.watch<ContactListCubit>().isBusy;
|
2024-01-30 17:03:14 -05:00
|
|
|
|
2024-04-12 20:55:05 -04:00
|
|
|
return SliderTile(
|
|
|
|
key: ObjectKey(contact),
|
|
|
|
disabled: tileDisabled,
|
|
|
|
selected: selected,
|
|
|
|
tileScale: ScaleKind.primary,
|
|
|
|
title: contact.editedProfile.name,
|
|
|
|
subtitle: contact.editedProfile.pronouns,
|
|
|
|
icon: Icons.person,
|
|
|
|
onTap: () async {
|
|
|
|
// Start a chat
|
|
|
|
final chatListCubit = context.read<ChatListCubit>();
|
2024-01-30 17:03:14 -05:00
|
|
|
|
2024-05-27 18:04:00 -04:00
|
|
|
await chatListCubit.getOrCreateChatSingleContact(contact: contact);
|
2024-04-12 20:55:05 -04:00
|
|
|
// Click over to chats
|
|
|
|
if (context.mounted) {
|
|
|
|
await MainPager.of(context)
|
|
|
|
?.pageController
|
|
|
|
.animateToPage(1, duration: 250.ms, curve: Curves.easeInOut);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
endActions: [
|
|
|
|
SliderTileAction(
|
|
|
|
icon: Icons.delete,
|
|
|
|
label: translate('button.delete'),
|
|
|
|
actionScale: ScaleKind.tertiary,
|
|
|
|
onPressed: (context) async {
|
|
|
|
final contactListCubit = context.read<ContactListCubit>();
|
|
|
|
final chatListCubit = context.read<ChatListCubit>();
|
2023-08-04 01:00:38 -04:00
|
|
|
|
2024-04-12 20:55:05 -04:00
|
|
|
// Remove any chats for this contact
|
|
|
|
await chatListCubit.deleteChat(
|
2024-05-27 18:04:00 -04:00
|
|
|
localConversationRecordKey: localConversationRecordKey);
|
2023-08-04 01:00:38 -04:00
|
|
|
|
2024-04-12 20:55:05 -04:00
|
|
|
// Delete the contact itself
|
|
|
|
await contactListCubit.deleteContact(contact: contact);
|
|
|
|
})
|
|
|
|
],
|
|
|
|
);
|
2023-08-04 01:00:38 -04:00
|
|
|
}
|
|
|
|
}
|