feat: support smol:// QR sharing, deep links and in-dialog scanning

This commit is contained in:
randogoth 2026-09-30 17:14:47 +03:00
parent 7d2a147fec
commit aa74e12ee7
20 changed files with 591 additions and 101 deletions

View file

@ -5,8 +5,6 @@ import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:smol_mail/data/providers/providers.dart";
import "package:smol_mail/presentation/routes/app_router.gr.dart";
import "package:smol_mail/presentation/theme/app_colors.dart";
import "package:smol_mail/shared/utils/snackbar.dart";
import "package:smol_mail/smol/errors.dart";
import "package:smol_mail/smol/ui.dart";
/// Contacts: the addresses bound to keys, with the trust badge and the number
@ -15,45 +13,8 @@ import "package:smol_mail/smol/ui.dart";
class ContactsScreen extends ConsumerWidget {
const ContactsScreen({super.key});
Future<void> _import(BuildContext context, WidgetRef ref) async {
final client = ref.read(clientProvider);
final controller = TextEditingController();
final text = await showDialog<String>(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: Theme.of(context).extension<AppColors>()!.cardFill,
title: const Text("Import contact"),
content: TextField(
controller: controller,
decoration: InputDecoration(
hintText: "smol://user@host/key",
filled: true,
fillColor: Theme.of(context).colorScheme.surface,
),
),
actions: [
TextButton(
onPressed: () => Navigator.of(ctx).pop(controller.text),
child: const Text("Import"),
),
],
),
);
if (text == null || text.trim().isEmpty) return;
try {
client.importContact(text);
ref.read(revisionProvider.notifier).bump();
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("contact imported (verified key)")),
);
}
} on SmolError catch (err) {
if (context.mounted) {
showErrorSnackBar(context, err.message);
}
}
}
void _import(BuildContext context) =>
AutoRouter.of(context).push(ImportContactDialogRoute());
@override
Widget build(BuildContext context, WidgetRef ref) {
@ -65,7 +26,7 @@ class ContactsScreen extends ConsumerWidget {
actions: [
IconButton(
tooltip: "Import smol:// address",
onPressed: () => _import(context, ref),
onPressed: () => _import(context),
icon: const Icon(Icons.person_add),
),
],