From 1b538931b18dbe0554402f6da16901b16168045b Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Wed, 3 Jan 2024 19:03:05 -0500 Subject: [PATCH] Confirmation box for link-based imports (#1232) --- lib/pages/home.dart | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/pages/home.dart b/lib/pages/home.dart index 0bba900..6d87a02 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -5,6 +5,7 @@ import 'package:app_links/app_links.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:obtainium/components/generated_form_modal.dart'; import 'package:obtainium/custom_errors.dart'; import 'package:obtainium/pages/add_app.dart'; import 'package:obtainium/pages/apps.dart'; @@ -76,14 +77,39 @@ class _HomePageState extends State { try { if (action == 'add') { await goToAddApp(data); - } else if (action == 'app') { - await context - .read() - .import('{ "apps": [${Uri.decodeComponent(data)}] }'); - } else if (action == 'apps') { - await context - .read() - .import('{ "apps": ${Uri.decodeComponent(data)} }'); + } else if (action == 'app' || action == 'apps') { + var dataStr = Uri.decodeComponent(data); + if (await showDialog( + context: context, + builder: (BuildContext ctx) { + return GeneratedFormModal( + title: tr('importX', args: [ + action == 'app' ? tr('app') : tr('appsString') + ]), + items: const [], + additionalWidgets: [ + ExpansionTile( + title: const Text('Raw JSON'), + children: [ + Text( + dataStr, + style: const TextStyle(fontFamily: 'monospace'), + ) + ], + ) + ], + ); + }) != + null) { + // ignore: use_build_context_synchronously + var result = await context.read().import( + action == 'app' + ? '{ "apps": [$dataStr] }' + : '{ "apps": $dataStr }'); + // ignore: use_build_context_synchronously + showMessage( + tr('importedX', args: [plural('apps', result.key)]), context); + } } else { throw ObtainiumError(tr('unknown')); }