From 911b06bfb650975c65742d9eaa3f34a71f9b7a54 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 17 Sep 2022 17:54:50 -0400 Subject: [PATCH] Slight tweak to import/export buttons --- lib/pages/import_export.dart | 139 ++++++++++++++++++++++------------- 1 file changed, 86 insertions(+), 53 deletions(-) diff --git a/lib/pages/import_export.dart b/lib/pages/import_export.dart index b1f8e49..9591df9 100644 --- a/lib/pages/import_export.dart +++ b/lib/pages/import_export.dart @@ -26,6 +26,16 @@ class _ImportExportPageState extends State { SourceProvider sourceProvider = SourceProvider(); var settingsProvider = context.read(); var appsProvider = context.read(); + var outlineButtonStyle = ButtonStyle( + shape: MaterialStateProperty.all( + StadiumBorder( + side: BorderSide( + width: 1, + color: Theme.of(context).colorScheme.primary, + ), + ), + ), + ); Future>> addApps(List urls) async { await settingsProvider.getInstallPermission(); @@ -53,59 +63,80 @@ class _ImportExportPageState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - ElevatedButton( - onPressed: appsProvider.apps.isEmpty || importInProgress - ? null - : () { - HapticFeedback.selectionClick(); - appsProvider.exportApps().then((String path) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('Exported to $path')), - ); - }); - }, - child: const Text('Obtainium Export')), - const SizedBox( - height: 8, + Row( + children: [ + Expanded( + child: TextButton( + style: outlineButtonStyle, + onPressed: appsProvider.apps.isEmpty || + importInProgress + ? null + : () { + HapticFeedback.selectionClick(); + appsProvider + .exportApps() + .then((String path) { + ScaffoldMessenger.of(context) + .showSnackBar( + SnackBar( + content: + Text('Exported to $path')), + ); + }); + }, + child: const Text('Obtainium Export'))), + const SizedBox( + width: 16, + ), + Expanded( + child: TextButton( + style: outlineButtonStyle, + onPressed: importInProgress + ? null + : () { + HapticFeedback.selectionClick(); + FilePicker.platform + .pickFiles() + .then((result) { + setState(() { + importInProgress = true; + }); + if (result != null) { + String data = + File(result.files.single.path!) + .readAsStringSync(); + try { + jsonDecode(data); + } catch (e) { + throw 'Invalid input'; + } + appsProvider + .importApps(data) + .then((value) { + ScaffoldMessenger.of(context) + .showSnackBar( + SnackBar( + content: Text( + '$value App${value == 1 ? '' : 's'} Imported')), + ); + }); + } else { + // User canceled the picker + } + }).catchError((e) { + ScaffoldMessenger.of(context) + .showSnackBar( + SnackBar(content: Text(e.toString())), + ); + }).whenComplete(() { + setState(() { + importInProgress = false; + }); + }); + }, + child: const Text('Obtainium Import'))) + ], ), - ElevatedButton( - onPressed: importInProgress - ? null - : () { - HapticFeedback.selectionClick(); - FilePicker.platform.pickFiles().then((result) { - setState(() { - importInProgress = true; - }); - if (result != null) { - String data = File(result.files.single.path!) - .readAsStringSync(); - try { - jsonDecode(data); - } catch (e) { - throw 'Invalid input'; - } - appsProvider.importApps(data).then((value) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - '$value App${value == 1 ? '' : 's'} Imported')), - ); - }); - } else { - // User canceled the picker - } - }).catchError((e) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(e.toString())), - ); - }).whenComplete(() { - setState(() { - importInProgress = false; - }); - }); - }, - child: const Text('Obtainium Import')), if (importInProgress) Column( children: const [ @@ -171,7 +202,9 @@ class _ImportExportPageState extends State { } }); }, - child: const Text('Import from URL List')), + child: const Text( + 'Import from URL List', + )), ...sourceProvider.massSources .map((source) => Column( crossAxisAlignment: CrossAxisAlignment.stretch,