diff --git a/lib/pages/import_export.dart b/lib/pages/import_export.dart index d919447..82dbfee 100644 --- a/lib/pages/import_export.dart +++ b/lib/pages/import_export.dart @@ -223,6 +223,97 @@ class _ImportExportPageState extends State { child: const Text( 'Import from URL List', )), + ...sourceProvider.sources + .where((element) => element.canSearch) + .map((source) => Column( + crossAxisAlignment: + CrossAxisAlignment.stretch, + children: [ + const SizedBox(height: 8), + TextButton( + onPressed: importInProgress + ? null + : () { + () async { + var values = await showDialog< + List>( + context: context, + builder: + (BuildContext ctx) { + return GeneratedFormModal( + title: + 'Search ${source.runtimeType}', + items: [ + [ + GeneratedFormItem( + label: + '${source.runtimeType} Search Query') + ] + ], + defaultValues: const [], + ); + }); + if (values != null && + values[0].isNotEmpty) { + setState(() { + importInProgress = true; + }); + var urls = await source + .search(values[0]); + if (urls.isNotEmpty) { + var selectedUrls = + await showDialog< + List< + String>?>( + context: context, + builder: + (BuildContext + ctx) { + return UrlSelectionModal( + urls: urls); + }); + if (selectedUrls != + null && + selectedUrls + .isNotEmpty) { + var errors = + await addApps( + selectedUrls); + if (errors.isEmpty) { + // ignore: use_build_context_synchronously + showError( + 'Imported ${selectedUrls.length} Apps', + context); + } else { + showDialog( + context: context, + builder: + (BuildContext + ctx) { + return ImportErrorDialog( + urlsLength: + selectedUrls + .length, + errors: + errors); + }); + } + } + } + } + }() + .catchError((e) { + showError(e, context); + }).whenComplete(() { + setState(() { + importInProgress = false; + }); + }); + }, + child: Text( + 'Search ${source.runtimeType}')) + ])) + .toList(), ...sourceProvider.massUrlSources .map((source) => Column( crossAxisAlignment: @@ -233,84 +324,73 @@ class _ImportExportPageState extends State { onPressed: importInProgress ? null : () { - showDialog( - context: context, - builder: - (BuildContext ctx) { - return GeneratedFormModal( - title: - 'Import ${source.name}', - items: source - .requiredArgs - .map((e) => [ - GeneratedFormItem( - label: e) - ]) - .toList(), - defaultValues: const [], - ); - }).then((values) { + () async { + var values = await showDialog( + context: context, + builder: + (BuildContext ctx) { + return GeneratedFormModal( + title: + 'Import ${source.name}', + items: + source + .requiredArgs + .map( + (e) => [ + GeneratedFormItem(label: e) + ]) + .toList(), + defaultValues: const [], + ); + }); if (values != null) { setState(() { importInProgress = true; }); - source - .getUrls(values) - .then((urls) { - showDialog?>( - context: context, - builder: - (BuildContext - ctx) { - return UrlSelectionModal( - urls: urls); - }) - .then((selectedUrls) { - if (selectedUrls != - null) { - addApps(selectedUrls) - .then((errors) { - if (errors - .isEmpty) { - showError( - 'Imported ${selectedUrls.length} Apps', - context); - } else { - showDialog( - context: - context, - builder: - (BuildContext - ctx) { - return ImportErrorDialog( - urlsLength: - selectedUrls - .length, - errors: - errors); - }); - } - }).whenComplete(() { - setState(() { - importInProgress = - false; + var urls = await source + .getUrls(values); + var selectedUrls = + await showDialog< + List?>( + context: context, + builder: + (BuildContext + ctx) { + return UrlSelectionModal( + urls: urls); }); - }); - } else { - setState(() { - importInProgress = - false; - }); - } - }); - }).catchError((e) { - setState(() { - importInProgress = - false; - }); - showError(e, context); - }); + if (selectedUrls != null) { + var errors = + await addApps( + selectedUrls); + if (errors.isEmpty) { + // ignore: use_build_context_synchronously + showError( + 'Imported ${selectedUrls.length} Apps', + context); + } else { + showDialog( + context: context, + builder: + (BuildContext + ctx) { + return ImportErrorDialog( + urlsLength: + selectedUrls + .length, + errors: + errors); + }); + } + } } + }() + .catchError((e) { + showError(e, context); + }).whenComplete(() { + setState(() { + importInProgress = false; + }); }); }, child: Text('Import ${source.name}'))