mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-05-13 19:52:20 -04:00
contacts work
This commit is contained in:
parent
f52094c105
commit
95ed8b28a0
6 changed files with 162 additions and 105 deletions
|
@ -1,7 +1,9 @@
|
|||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
|
@ -10,37 +12,42 @@ import '../tools/tools.dart';
|
|||
|
||||
class ContactInvitationDisplayDialog extends ConsumerStatefulWidget {
|
||||
const ContactInvitationDisplayDialog({
|
||||
required this.name,
|
||||
required this.message,
|
||||
required this.generator,
|
||||
super.key,
|
||||
});
|
||||
|
||||
// EncryptionKeyType _encryptionKeyType = EncryptionKeyType.none;
|
||||
// _encryptionKey = '';
|
||||
final String name;
|
||||
final String message;
|
||||
final Future<Uint8List> generator;
|
||||
|
||||
@override
|
||||
ContactInvitationDisplayDialogState createState() =>
|
||||
ContactInvitationDisplayDialogState();
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties
|
||||
..add(StringProperty('name', name))
|
||||
..add(StringProperty('message', message))
|
||||
..add(DiagnosticsProperty<Future<Uint8List>?>('generator', generator));
|
||||
}
|
||||
}
|
||||
|
||||
class ContactInvitationDisplayDialogState
|
||||
extends ConsumerState<ContactInvitationDisplayDialog> {
|
||||
final focusNode = FocusNode();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
Future<void>? _generateFuture;
|
||||
late final FutureProvider<Uint8List?> _generateFutureProvider;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (_generateFuture == null) {
|
||||
_generateFuture = _generate();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _generate() async {
|
||||
// Generate invitation
|
||||
|
||||
setState(() {
|
||||
_generateFuture = null;
|
||||
});
|
||||
_generateFutureProvider =
|
||||
FutureProvider<Uint8List>((ref) async => widget.generator);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -54,21 +61,35 @@ class ContactInvitationDisplayDialogState
|
|||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
|
||||
final signedContactInvitationBytesV = ref.watch(_generateFutureProvider);
|
||||
final cardsize = MediaQuery.of(context).size.shortestSide - 24;
|
||||
//
|
||||
|
||||
return Dialog(
|
||||
backgroundColor: Colors.white,
|
||||
child: SizedBox(
|
||||
width: cardsize,
|
||||
height: cardsize,
|
||||
child: Form(
|
||||
child: signedContactInvitationBytesV.when(
|
||||
loading: () => waitingPage(context),
|
||||
data: (data) => Form(
|
||||
key: formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [Text("Contact Invitation")]))
|
||||
.withModalHUD(context, _generateFuture != null)));
|
||||
children: [Text("Contact Invitation")])),
|
||||
error: (e, s) {
|
||||
Navigator.of(context).pop();
|
||||
showErrorToast(
|
||||
context, "Failed to generate contact invitation: $e");
|
||||
return Text("");
|
||||
})));
|
||||
}
|
||||
|
||||
@override
|
||||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
|
||||
super.debugFillProperties(properties);
|
||||
properties
|
||||
..add(DiagnosticsProperty<FocusNode>('focusNode', focusNode))
|
||||
..add(DiagnosticsProperty<GlobalKey<FormState>>('formKey', formKey));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue