veilidchat/lib/components/contact_invitation_item_widget.dart

128 lines
5.3 KiB
Dart
Raw Normal View History

2023-08-05 01:00:46 -04:00
import 'package:flutter/foundation.dart';
2023-08-04 01:00:38 -04:00
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-05 01:00:46 -04:00
import '../providers/account.dart';
2023-08-05 23:58:13 -04:00
import '../providers/contact_invite.dart';
2023-08-05 01:00:46 -04:00
import '../tools/tools.dart';
import 'contact_invitation_display.dart';
2023-08-04 01:00:38 -04:00
class ContactInvitationItemWidget extends ConsumerWidget {
const ContactInvitationItemWidget(
{required this.contactInvitationRecord, super.key});
final proto.ContactInvitationRecord contactInvitationRecord;
2023-08-05 01:00:46 -04:00
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<proto.ContactInvitationRecord>(
'contactInvitationRecord', contactInvitationRecord));
}
2023-08-04 01:00:38 -04:00
@override
// ignore: prefer_expression_function_bodies
Widget build(BuildContext context, WidgetRef ref) {
2023-08-05 01:00:46 -04:00
final theme = Theme.of(context);
2023-08-05 23:58:13 -04:00
//final textTheme = theme.textTheme;
2023-08-05 01:00:46 -04:00
final scale = theme.extension<ScaleScheme>()!;
2023-08-04 01:00:38 -04:00
2023-08-05 01:00:46 -04:00
return Container(
clipBehavior: Clip.antiAlias,
decoration: ShapeDecoration(
2023-09-24 15:30:54 -04:00
color: scale.tertiaryScale.subtleBorder,
2023-08-05 01:00:46 -04:00
shape: RoundedRectangleBorder(
2023-09-24 15:30:54 -04:00
borderRadius: BorderRadius.circular(8),
2023-08-05 01:00:46 -04:00
)),
child: Slidable(
// Specify a key if the Slidable is dismissible.
key: ObjectKey(contactInvitationRecord),
endActionPane: ActionPane(
// A motion is a widget used to control how the pane animates.
motion: const DrawerMotion(),
2023-08-04 01:00:38 -04:00
2023-08-05 01:00:46 -04:00
// A pane can dismiss the Slidable.
//dismissible: DismissiblePane(onDismissed: () {}),
// All actions are defined in the children parameter.
children: [
// A SlidableAction can have an icon and/or a label.
SlidableAction(
onPressed: (context) async {
final activeAccountInfo =
await ref.read(fetchActiveAccountProvider.future);
if (activeAccountInfo != null) {
await deleteContactInvitation(
2023-08-05 19:34:00 -04:00
accepted: false,
2023-08-05 01:00:46 -04:00
activeAccountInfo: activeAccountInfo,
contactInvitationRecord: contactInvitationRecord);
ref.invalidate(fetchContactInvitationRecordsProvider);
}
},
backgroundColor: scale.tertiaryScale.background,
foregroundColor: scale.tertiaryScale.text,
icon: Icons.delete,
label: translate('button.delete'),
padding: const EdgeInsets.all(2)),
],
2023-08-04 01:00:38 -04:00
),
2023-08-05 01:00:46 -04:00
// startActionPane: ActionPane(
// motion: const DrawerMotion(),
// children: [
// SlidableAction(
// // An action can be bigger than the others.
// flex: 2,
// onPressed: (context) => (),
// backgroundColor: Color(0xFF7BC043),
// foregroundColor: Colors.white,
// icon: Icons.archive,
// label: 'Archive',
// ),
// SlidableAction(
// onPressed: (context) => (),
// backgroundColor: Color(0xFF0392CF),
// foregroundColor: Colors.white,
// icon: Icons.save,
// label: 'Save',
// ),
// ],
// ),
2023-08-04 01:00:38 -04:00
2023-08-05 01:00:46 -04:00
// The child of the Slidable is what the user sees when the
// component is not dragged.
child: ListTile(
//title: Text(translate('contact_list.invitation')),
onTap: () async {
final activeAccountInfo =
await ref.read(fetchActiveAccountProvider.future);
if (activeAccountInfo != null) {
// 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),
));
}
},
2023-08-09 02:33:31 -04:00
title: Text(
contactInvitationRecord.message.isEmpty
? translate('contact_list.invitation')
: contactInvitationRecord.message,
softWrap: true,
),
2023-08-05 01:00:46 -04:00
iconColor: scale.tertiaryScale.background,
textColor: scale.tertiaryScale.text,
//Text(Timestamp.fromInt64(contactInvitationRecord.expiration) / ),
leading: const Icon(Icons.person_add))));
2023-08-04 01:00:38 -04:00
}
}