veilidchat/lib/contact_invitation/views/contact_invitation_item_widget.dart

127 lines
5.1 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';
2024-01-29 22:38:19 -05:00
import 'package:flutter_bloc/flutter_bloc.dart';
2023-08-04 01:00:38 -04:00
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:flutter_translate/flutter_translate.dart';
2024-01-09 20:58:27 -05:00
import '../../proto/proto.dart' as proto;
import '../../theme/theme.dart';
2024-01-29 22:38:19 -05:00
import '../contact_invitation.dart';
2023-08-04 01:00:38 -04:00
2024-01-09 20:58:27 -05:00
class ContactInvitationItemWidget extends StatelessWidget {
2023-08-04 01:00:38 -04:00
const ContactInvitationItemWidget(
2024-02-27 12:45:58 -05:00
{required this.contactInvitationRecord,
required this.disabled,
super.key});
2023-08-04 01:00:38 -04:00
final proto.ContactInvitationRecord contactInvitationRecord;
2024-02-27 12:45:58 -05:00
final bool disabled;
2023-08-04 01:00:38 -04:00
2023-08-05 01:00:46 -04:00
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
2024-02-27 12:45:58 -05:00
properties
..add(DiagnosticsProperty<proto.ContactInvitationRecord>(
'contactInvitationRecord', contactInvitationRecord))
..add(DiagnosticsProperty<bool>('disabled', disabled));
2023-08-05 01:00:46 -04:00
}
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) {
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(
2024-02-27 21:37:39 -05:00
onPressed: disabled
? null
: (context) async {
final contactInvitationListCubit =
context.read<ContactInvitationListCubit>();
await contactInvitationListCubit.deleteInvitation(
accepted: false,
contactRequestInboxRecordKey:
contactInvitationRecord
.contactRequestInbox.recordKey
.toVeilid());
},
2023-08-05 01:00:46 -04:00
backgroundColor: scale.tertiaryScale.background,
2024-04-07 23:16:06 -04:00
foregroundColor: scale.tertiaryScale.appText,
2023-08-05 01:00:46 -04:00
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')),
2024-02-27 21:37:39 -05:00
onTap: disabled
? null
: () async {
if (!context.mounted) {
return;
}
2024-04-05 22:03:04 -04:00
await ContactInvitationDisplayDialog.show(
2024-02-27 21:37:39 -05:00
context: context,
2024-04-05 22:03:04 -04:00
message: contactInvitationRecord.message,
create: (context) => InvitationGeneratorCubit.value(
Uint8List.fromList(
contactInvitationRecord.invitation)));
2024-02-27 21:37:39 -05:00
},
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,
2024-04-07 23:16:06 -04:00
textColor: scale.tertiaryScale.appText,
2023-08-05 01:00:46 -04:00
//Text(Timestamp.fromInt64(contactInvitationRecord.expiration) / ),
leading: const Icon(Icons.person_add))));
2023-08-04 01:00:38 -04:00
}
}