veilidchat/lib/contact_invitation/views/contact_invitation_display.dart

122 lines
4.7 KiB
Dart
Raw Normal View History

2023-09-22 11:20:28 -04:00
import 'dart:math';
2023-08-03 00:49:48 -04:00
2023-08-09 02:33:31 -04:00
import 'package:awesome_extensions/awesome_extensions.dart';
2023-08-04 01:00:38 -04:00
import 'package:basic_utils/basic_utils.dart';
2023-08-01 00:39:50 -04:00
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
2023-08-04 01:00:38 -04:00
import 'package:flutter/services.dart';
2024-04-05 22:03:04 -04:00
import 'package:flutter_bloc/flutter_bloc.dart';
2023-08-02 21:09:28 -04:00
import 'package:flutter_translate/flutter_translate.dart';
2023-08-04 01:00:38 -04:00
import 'package:qr_flutter/qr_flutter.dart';
2024-01-09 20:58:27 -05:00
import 'package:veilid_support/veilid_support.dart';
2023-08-01 00:39:50 -04:00
import '../../theme/theme.dart';
2024-01-09 20:58:27 -05:00
import '../../tools/tools.dart';
2024-03-24 12:13:27 -04:00
import '../contact_invitation.dart';
2024-01-29 22:38:19 -05:00
2024-04-05 22:03:04 -04:00
class ContactInvitationDisplayDialog extends StatelessWidget {
const ContactInvitationDisplayDialog._({
required this.modalContext,
2023-08-03 00:49:48 -04:00
required this.message,
2023-08-02 21:09:28 -04:00
});
2024-04-05 22:03:04 -04:00
final BuildContext modalContext;
2023-08-03 00:49:48 -04:00
final String message;
2023-08-02 21:09:28 -04:00
2023-08-03 00:49:48 -04:00
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
2024-04-05 22:03:04 -04:00
properties
..add(StringProperty('message', message))
..add(DiagnosticsProperty<BuildContext>('modalContext', modalContext));
2023-08-01 00:39:50 -04:00
}
2023-08-04 01:00:38 -04:00
String makeTextInvite(String message, Uint8List data) {
final invite = StringUtils.addCharAtPosition(
base64UrlNoPadEncode(data), '\n', 40,
repeat: true);
final msg = message.isNotEmpty ? '$message\n' : '';
return '$msg'
2023-08-05 01:00:46 -04:00
'--- BEGIN VEILIDCHAT CONTACT INVITE ----\n'
2023-08-04 01:00:38 -04:00
'$invite\n'
2023-08-05 01:00:46 -04:00
'---- END VEILIDCHAT CONTACT INVITE -----\n';
2023-08-04 01:00:38 -04:00
}
2023-08-01 00:39:50 -04:00
@override
2023-08-02 21:09:28 -04:00
// ignore: prefer_expression_function_bodies
Widget build(BuildContext context) {
final theme = Theme.of(context);
2023-08-05 23:58:13 -04:00
//final scale = theme.extension<ScaleScheme>()!;
2023-08-04 01:00:38 -04:00
final textTheme = theme.textTheme;
2024-01-29 22:38:19 -05:00
final signedContactInvitationBytesV =
context.watch<InvitationGeneratorCubit>().state;
2023-09-22 11:20:28 -04:00
final cardsize =
min<double>(MediaQuery.of(context).size.shortestSide - 48.0, 400);
2023-08-02 21:09:28 -04:00
2024-04-05 22:03:04 -04:00
return PopControl(
dismissible: !signedContactInvitationBytesV.isLoading,
child: Dialog(
backgroundColor: Colors.white,
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: cardsize,
maxWidth: cardsize,
minHeight: cardsize,
maxHeight: cardsize),
child: signedContactInvitationBytesV.when(
loading: buildProgressIndicator,
data: (data) => Column(children: [
FittedBox(
child: Text(
translate(
'create_invitation_dialog.contact_invitation'),
style: textTheme.headlineSmall!
.copyWith(color: Colors.black)))
.paddingAll(8),
FittedBox(
child: QrImageView.withQr(
size: 300,
qr: QrCode.fromUint8List(
data: data,
errorCorrectLevel:
QrErrorCorrectLevel.L)))
.expanded(),
Text(message,
softWrap: true,
style: textTheme.labelLarge!
.copyWith(color: Colors.black))
.paddingAll(8),
ElevatedButton.icon(
icon: const Icon(Icons.copy),
label: Text(translate(
'create_invitation_dialog.copy_invitation')),
onPressed: () async {
showInfoToast(
context,
2024-01-29 22:38:19 -05:00
translate(
2024-04-05 22:03:04 -04:00
'create_invitation_dialog.invitation_copied'));
await Clipboard.setData(ClipboardData(
text: makeTextInvite(message, data)));
},
).paddingAll(16),
]),
error: errorPage))));
2023-08-03 00:49:48 -04:00
}
2024-04-05 22:03:04 -04:00
static Future<void> show(
{required BuildContext context,
required InvitationGeneratorCubit Function(BuildContext) create,
required String message}) async {
await showPopControlDialog<void>(
context: context,
builder: (context) => BlocProvider(
create: create,
child: ContactInvitationDisplayDialog._(
modalContext: context,
message: message,
)));
2023-08-01 00:39:50 -04:00
}
}