diff --git a/lib/widgets/homePage.dart b/lib/widgets/homePage.dart index 4ad8948..19c28bd 100644 --- a/lib/widgets/homePage.dart +++ b/lib/widgets/homePage.dart @@ -1,3 +1,4 @@ +import 'package:file_selector/file_selector.dart'; import 'package:flutter/material.dart'; import 'package:reciper/widgets/extractRecipeButton.dart'; import 'package:reciper/widgets/settings.dart'; @@ -6,6 +7,8 @@ import 'newRecipeButton.dart'; import '../database.dart'; import '../models/recipe.dart'; import 'recipesListView.dart'; +import 'package:path_provider/path_provider.dart'; +import 'dart:io'; class HomePage extends StatefulWidget { const HomePage({super.key}); @@ -60,7 +63,7 @@ class _HomePageState extends State { drawer: Drawer( child: Settings( backup: backup, - restore: restore, + restore: import, )), body: SingleChildScrollView( child: Column( @@ -111,15 +114,33 @@ class _HomePageState extends State { } Future backup() async { + Directory appDocumentsDirectory = + await getApplicationDocumentsDirectory(); // 1 + String appDocumentsPath = appDocumentsDirectory.path; + String filePath = '$appDocumentsPath/Reciper_Export.json'; + + File file = File(filePath); + DatabaseService db = DatabaseService(); db.generateBackup().then((String result) { - Share.share(result); + file.writeAsString(result); + Share.shareXFiles([XFile(filePath)]); }); } - Future restore(String backup) async { - DatabaseService db = DatabaseService(); - db.restoreBackup(backup); - loadRecipes(); + Future import() async { + const XTypeGroup typeGroup = XTypeGroup( + label: 'Reciper export', + extensions: ['json'], + ); + final XFile? file = + await openFile(acceptedTypeGroups: [typeGroup]); + + if (file != null) { + String backupContent = await file.readAsString(); + DatabaseService db = DatabaseService(); + db.restoreBackup(backupContent); + loadRecipes(); + } } } diff --git a/lib/widgets/settings.dart b/lib/widgets/settings.dart index 42449c1..347b1f0 100644 --- a/lib/widgets/settings.dart +++ b/lib/widgets/settings.dart @@ -49,37 +49,8 @@ class _SettingsState extends State { child: Column( children: [ ListTile( - title: const Text("Restore backup"), - onTap: () => showDialog( - context: context, - builder: (context) => AlertDialog( - title: const Text("Import recipes"), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - TextField( - controller: backupCodeController, - decoration: const InputDecoration( - hintText: "Past Backup Code Here"), - ), - ], - ), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context, 'Cancel'), - child: const Text('Cancel'), - ), - TextButton( - onPressed: () { - widget.restore(backupCodeController.text); - Navigator.pop(context, 'ok'); - }, - child: const Text('OK'), - ), - ], - ), - ), - ), + title: const Text("Import recipes"), + onTap: () => widget.restore()), ], ), ), diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 4c0025f..9f99dda 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,10 +6,14 @@ #include "generated_plugin_registrant.h" +#include #include #include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); + file_selector_plugin_register_with_registrar(file_selector_linux_registrar); g_autoptr(FlPluginRegistrar) sqlite3_flutter_libs_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "Sqlite3FlutterLibsPlugin"); sqlite3_flutter_libs_plugin_register_with_registrar(sqlite3_flutter_libs_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index ad279a8..3ff88a3 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + file_selector_linux sqlite3_flutter_libs url_launcher_linux ) diff --git a/pubspec.lock b/pubspec.lock index 9dc279e..7499619 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -153,6 +153,70 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0" + file_selector: + dependency: "direct main" + description: + name: file_selector + sha256: "5019692b593455127794d5718304ff1ae15447dea286cdda9f0db2a796a1b828" + url: "https://pub.dev" + source: hosted + version: "1.0.3" + file_selector_android: + dependency: transitive + description: + name: file_selector_android + sha256: "1cd66575f063b689e041aec836905ba7be18d76c9f0634d0d75daec825f67095" + url: "https://pub.dev" + source: hosted + version: "0.5.0+7" + file_selector_ios: + dependency: transitive + description: + name: file_selector_ios + sha256: b015154e6d9fddbc4d08916794df170b44531798c8dd709a026df162d07ad81d + url: "https://pub.dev" + source: hosted + version: "0.5.1+8" + file_selector_linux: + dependency: transitive + description: + name: file_selector_linux + sha256: "045d372bf19b02aeb69cacf8b4009555fb5f6f0b7ad8016e5f46dd1387ddd492" + url: "https://pub.dev" + source: hosted + version: "0.9.2+1" + file_selector_macos: + dependency: transitive + description: + name: file_selector_macos + sha256: b15c3da8bd4908b9918111fa486903f5808e388b8d1c559949f584725a6594d6 + url: "https://pub.dev" + source: hosted + version: "0.9.3+3" + file_selector_platform_interface: + dependency: transitive + description: + name: file_selector_platform_interface + sha256: a3994c26f10378a039faa11de174d7b78eb8f79e4dd0af2a451410c1a5c3f66b + url: "https://pub.dev" + source: hosted + version: "2.6.2" + file_selector_web: + dependency: transitive + description: + name: file_selector_web + sha256: "619e431b224711a3869e30dbd7d516f5f5a4f04b265013a50912f39e1abc88c8" + url: "https://pub.dev" + source: hosted + version: "0.9.4+1" + file_selector_windows: + dependency: transitive + description: + name: file_selector_windows + sha256: d3547240c20cabf205c7c7f01a50ecdbc413755814d6677f3cb366f04abcead0 + url: "https://pub.dev" + source: hosted + version: "0.9.3+1" fixnum: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 16c736b..00ff44b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.2 +version: 1.1.0 environment: sdk: '>=3.3.1 <4.0.0' @@ -45,6 +45,7 @@ dependencies: recipe_extractor: ^2.0.0 url_launcher: ^6.2.5 share_plus: ^8.0.3 + file_selector: ^1.0.3 flutter_icons: