2023-09-23 12:56:54 -04:00
|
|
|
import 'dart:async';
|
2023-09-27 13:34:19 -04:00
|
|
|
import 'dart:typed_data';
|
2023-09-23 12:56:54 -04:00
|
|
|
|
|
|
|
import 'package:awesome_extensions/awesome_extensions.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter_translate/flutter_translate.dart';
|
|
|
|
|
|
|
|
import '../tools/tools.dart';
|
2023-09-27 13:34:19 -04:00
|
|
|
import 'invite_dialog.dart';
|
2023-09-23 12:56:54 -04:00
|
|
|
|
|
|
|
class ScanInviteDialog extends ConsumerStatefulWidget {
|
|
|
|
const ScanInviteDialog({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
ScanInviteDialogState createState() => ScanInviteDialogState();
|
2023-09-27 13:34:19 -04:00
|
|
|
|
|
|
|
static Future<void> show(BuildContext context) async {
|
|
|
|
await showStyledDialog<void>(
|
|
|
|
context: context,
|
|
|
|
title: translate('scan_invite_dialog.title'),
|
|
|
|
child: const ScanInviteDialog());
|
|
|
|
}
|
2023-09-23 12:56:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class ScanInviteDialogState extends ConsumerState<ScanInviteDialog> {
|
2023-09-27 13:34:19 -04:00
|
|
|
// final _pasteTextController = TextEditingController();
|
2023-09-23 12:56:54 -04:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2023-09-27 13:34:19 -04:00
|
|
|
// Future<void> _onPasteChanged(
|
|
|
|
// String text,
|
|
|
|
// Future<void> Function({
|
|
|
|
// required Uint8List inviteData,
|
|
|
|
// }) validateInviteData) async {
|
|
|
|
// final lines = text.split('\n');
|
|
|
|
// if (lines.isEmpty) {
|
2023-09-23 12:56:54 -04:00
|
|
|
// return;
|
|
|
|
// }
|
2023-09-27 13:34:19 -04:00
|
|
|
|
|
|
|
// var firstline =
|
|
|
|
// lines.indexWhere((element) => element.contains('BEGIN VEILIDCHAT'));
|
|
|
|
// firstline += 1;
|
|
|
|
|
|
|
|
// var lastline =
|
|
|
|
// lines.indexWhere((element) => element.contains('END VEILIDCHAT'));
|
|
|
|
// if (lastline == -1) {
|
|
|
|
// lastline = lines.length;
|
2023-09-23 12:56:54 -04:00
|
|
|
// }
|
2023-09-27 13:34:19 -04:00
|
|
|
// if (lastline <= firstline) {
|
2023-09-23 12:56:54 -04:00
|
|
|
// return;
|
|
|
|
// }
|
2023-09-27 13:34:19 -04:00
|
|
|
// final inviteDataBase64 = lines.sublist(firstline, lastline).join();
|
|
|
|
// final inviteData = base64UrlNoPadDecode(inviteDataBase64);
|
2023-09-23 12:56:54 -04:00
|
|
|
|
2023-09-27 13:34:19 -04:00
|
|
|
// await validateInviteData(inviteData: inviteData);
|
2023-09-23 12:56:54 -04:00
|
|
|
// }
|
|
|
|
|
2023-09-27 13:34:19 -04:00
|
|
|
void onValidationCancelled() {
|
|
|
|
// _pasteTextController.clear();
|
2023-09-23 12:56:54 -04:00
|
|
|
}
|
|
|
|
|
2023-09-27 13:34:19 -04:00
|
|
|
void onValidationSuccess() {
|
|
|
|
//_pasteTextController.clear();
|
2023-09-23 12:56:54 -04:00
|
|
|
}
|
2023-09-27 13:34:19 -04:00
|
|
|
void onValidationFailed() {
|
|
|
|
//_pasteTextController.clear();
|
2023-09-23 12:56:54 -04:00
|
|
|
}
|
2023-09-27 13:34:19 -04:00
|
|
|
bool inviteControlIsValid() => false; // _pasteTextController.text.isNotEmpty;
|
2023-09-23 12:56:54 -04:00
|
|
|
|
2023-09-27 13:34:19 -04:00
|
|
|
Widget buildInviteControl(
|
|
|
|
BuildContext context,
|
|
|
|
InviteDialogState dialogState,
|
|
|
|
Future<void> Function({required Uint8List inviteData})
|
|
|
|
validateInviteData) {
|
2023-09-23 12:56:54 -04:00
|
|
|
final theme = Theme.of(context);
|
|
|
|
//final scale = theme.extension<ScaleScheme>()!;
|
|
|
|
final textTheme = theme.textTheme;
|
|
|
|
//final height = MediaQuery.of(context).size.height;
|
|
|
|
|
2023-09-27 13:34:19 -04:00
|
|
|
return Column(mainAxisSize: MainAxisSize.min, children: [
|
|
|
|
Text(
|
|
|
|
translate('scan_invite_dialog.scan_invite_here'),
|
|
|
|
).paddingLTRB(0, 0, 0, 8),
|
|
|
|
// Container(
|
|
|
|
// constraints: const BoxConstraints(maxHeight: 200),
|
|
|
|
// child: TextField(
|
|
|
|
// enabled: !dialogState.isValidating,
|
|
|
|
// onChanged: (text) => _onPasteChanged(text, validateInviteData),
|
|
|
|
// style: textTheme.labelSmall!
|
|
|
|
// .copyWith(fontFamily: 'Victor Mono', fontSize: 11),
|
|
|
|
// keyboardType: TextInputType.multiline,
|
|
|
|
// maxLines: null,
|
|
|
|
// controller: _pasteTextController,
|
|
|
|
// decoration: const InputDecoration(
|
|
|
|
// border: OutlineInputBorder(),
|
|
|
|
// hintText: '--- BEGIN VEILIDCHAT CONTACT INVITE ----\n'
|
|
|
|
// 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n'
|
|
|
|
// '---- END VEILIDCHAT CONTACT INVITE -----\n',
|
|
|
|
// //labelText: translate('paste_invite_dialog.paste')
|
|
|
|
// ),
|
|
|
|
// )).paddingLTRB(0, 0, 0, 8)
|
|
|
|
]);
|
2023-09-23 12:56:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2023-09-27 13:34:19 -04:00
|
|
|
// ignore: prefer_expression_function_bodies
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return InviteDialog(
|
|
|
|
onValidationCancelled: onValidationCancelled,
|
|
|
|
onValidationSuccess: onValidationSuccess,
|
|
|
|
onValidationFailed: onValidationFailed,
|
|
|
|
inviteControlIsValid: inviteControlIsValid,
|
|
|
|
buildInviteControl: buildInviteControl);
|
2023-09-23 12:56:54 -04:00
|
|
|
}
|
|
|
|
}
|