From 996abd1127786a475abe598584e0e2a4c66109be Mon Sep 17 00:00:00 2001 From: JdM Date: Mon, 8 Apr 2024 16:20:33 +0200 Subject: [PATCH] back homepage after recipe update --- lib/widgets/homePage.dart | 33 ++++- lib/widgets/recipeEditorPage.dart | 6 +- lib/widgets/settings.dart | 142 +++++++++++++++++++ linux/flutter/generated_plugin_registrant.cc | 4 + linux/flutter/generated_plugins.cmake | 1 + pubspec.lock | 103 +++++++++++--- pubspec.yaml | 3 +- 7 files changed, 266 insertions(+), 26 deletions(-) create mode 100644 lib/widgets/settings.dart diff --git a/lib/widgets/homePage.dart b/lib/widgets/homePage.dart index 153059b..385943d 100644 --- a/lib/widgets/homePage.dart +++ b/lib/widgets/homePage.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:reciper/widgets/extractRecipeButton.dart'; +import 'package:reciper/widgets/settings.dart'; +import 'package:share/share.dart'; import 'newRecipeButton.dart'; import '../database.dart'; import '../models/recipe.dart'; @@ -30,14 +32,14 @@ class _HomePageState extends State { appBar: AppBar( title: const Text("Reciper"), centerTitle: true, - leading: IconButton( - onPressed: () { - setState(() { - displaySearchField = !displaySearchField; - }); - }, - icon: const Icon(Icons.search)), actions: [ + IconButton( + onPressed: () { + setState(() { + displaySearchField = !displaySearchField; + }); + }, + icon: const Icon(Icons.search)), if (selectedRecipes.isNotEmpty) IconButton( onPressed: () { @@ -56,6 +58,11 @@ class _HomePageState extends State { NewRecipeButton(reloadRecipes: loadRecipes), ], ), + drawer: Drawer( + child: Settings( + backup: backup, + restore: restore, + )), body: Column( children: [ Visibility( @@ -106,4 +113,16 @@ class _HomePageState extends State { selectedRecipes = []; }); } + + Future backup() async { + DatabaseService db = DatabaseService(); + db.generateBackup().then((String result) { + Share.share(result); + }); + } + + Future restore(String backup) async { + DatabaseService db = DatabaseService(); + db.restoreBackup(backup); + } } diff --git a/lib/widgets/recipeEditorPage.dart b/lib/widgets/recipeEditorPage.dart index 6017b94..df5ccaa 100644 --- a/lib/widgets/recipeEditorPage.dart +++ b/lib/widgets/recipeEditorPage.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:reciper/database.dart'; import 'package:reciper/models/recipe.dart'; +import 'package:reciper/widgets/homePage.dart'; class RecipeEditorPage extends StatefulWidget { final String initialTitle; @@ -51,7 +52,10 @@ class _RecipeEditorPageState extends State { steps: steps, ingredients: ingredients)); } - Navigator.pop(context); + + Navigator.of(context).push( + MaterialPageRoute(builder: (context) => HomePage()), + ); } }, icon: const Icon(Icons.check)) diff --git a/lib/widgets/settings.dart b/lib/widgets/settings.dart new file mode 100644 index 0000000..96d0ebe --- /dev/null +++ b/lib/widgets/settings.dart @@ -0,0 +1,142 @@ +import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher.dart'; + +class Settings extends StatefulWidget { + final Function backup; + final Function restore; + + const Settings({Key? key, required this.backup, required this.restore}); + + @override + State createState() => _SettingsState(); +} + +class _SettingsState extends State { + int _displayedTabIndex = 0; + + void setDisplayedTab(int index) { + setState(() { + if (_displayedTabIndex == index) { + _displayedTabIndex = 0; + } else { + _displayedTabIndex = index; + } + }); + } + + @override + Widget build(BuildContext context) { + TextEditingController backupCodeController = TextEditingController(); + + return Scaffold( + appBar: AppBar( + title: const Text('Settings'), + ), + body: SingleChildScrollView( + child: Column( + children: [ + ListTile( + selected: _displayedTabIndex == 1, + onTap: () { + setDisplayedTab(1); + }, + title: const Text("Import"), + ), + Visibility( + visible: _displayedTabIndex == 1, + child: Container( + margin: const EdgeInsets.only(left: 20), + child: Column( + children: [ + ListTile( + title: const Text("Restore backup"), + onTap: () => showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text("Restore backup"), + 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'), + ), + ], + ), + ), + ), + ], + ), + ), + ), + ListTile( + selected: _displayedTabIndex == 2, + onTap: () { + setDisplayedTab(2); + }, + title: const Text("Export"), + ), + Visibility( + visible: _displayedTabIndex == 2, + child: Container( + margin: const EdgeInsets.only(left: 20), + child: Column( + children: [ + ListTile( + title: const Text("Backup"), + onTap: () => widget.backup(), + ), + ], + ), + ), + ), + ListTile( + selected: _displayedTabIndex == 3, + onTap: () { + setDisplayedTab(3); + }, + title: const Text("About"), + ), + Visibility( + visible: _displayedTabIndex == 3, + child: Container( + margin: const EdgeInsets.only(left: 20), + child: Column( + children: [ + const ListTile( + title: Text( + "Reciper is an open source, simple (but powerful), privacy friendly Recipe management app developed with ❤️ by Judemont and Rdemont"), + ), + ListTile( + title: const Text( + "Source code (GitHub)", + style: TextStyle(color: Colors.blue), + ), + onTap: () => launchUrl( + Uri.parse('https://github.com/judemont/tasker')), + ) + ], + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 2c1ec4f..4c0025f 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -7,9 +7,13 @@ #include "generated_plugin_registrant.h" #include +#include void fl_register_plugins(FlPluginRegistry* registry) { 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); + g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); + url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 7ea2a80..ad279a8 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST sqlite3_flutter_libs + url_launcher_linux ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/pubspec.lock b/pubspec.lock index b88e7e5..4a026d4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -33,14 +33,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" - beautiful_soup_dart: - dependency: transitive - description: - name: beautiful_soup_dart - sha256: "57e23946c85776dd9515a4e9a14263fff37dbedbd559bc4412bf565886e12b10" - url: "https://pub.dev" - source: hosted - version: "0.3.0" boolean_selector: dependency: transitive description: @@ -171,6 +163,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" html: dependency: transitive description: @@ -251,14 +248,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" - marmiteur: - dependency: "direct main" - description: - name: marmiteur - sha256: eb7185fa74641a16e59276c1bad9cf65daa58b70fa4aef07332a3055cb223bb3 - url: "https://pub.dev" - source: hosted - version: "3.0.0" matcher: dependency: transitive description: @@ -283,6 +272,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.0" + mime: + dependency: transitive + description: + name: mime + sha256: "2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2" + url: "https://pub.dev" + source: hosted + version: "1.0.5" path: dependency: "direct main" description: @@ -379,6 +376,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.0" + share: + dependency: "direct main" + description: + name: share + sha256: "97e6403f564ed1051a01534c2fc919cb6e40ea55e60a18ec23cee6e0ce19f4be" + url: "https://pub.dev" + source: hosted + version: "2.0.4" sky_engine: dependency: transitive description: flutter @@ -488,6 +493,70 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.2" + url_launcher: + dependency: "direct main" + description: + name: url_launcher + sha256: "0ecc004c62fd3ed36a2ffcbe0dd9700aee63bd7532d0b642a488b1ec310f492e" + url: "https://pub.dev" + source: hosted + version: "6.2.5" + url_launcher_android: + dependency: transitive + description: + name: url_launcher_android + sha256: d4ed0711849dd8e33eb2dd69c25db0d0d3fdc37e0a62e629fe32f57a22db2745 + url: "https://pub.dev" + source: hosted + version: "6.3.0" + url_launcher_ios: + dependency: transitive + description: + name: url_launcher_ios + sha256: "9149d493b075ed740901f3ee844a38a00b33116c7c5c10d7fb27df8987fb51d5" + url: "https://pub.dev" + source: hosted + version: "6.2.5" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811 + url: "https://pub.dev" + source: hosted + version: "3.1.1" + url_launcher_macos: + dependency: transitive + description: + name: url_launcher_macos + sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234 + url: "https://pub.dev" + source: hosted + version: "3.1.0" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + sha256: "3692a459204a33e04bc94f5fb91158faf4f2c8903281ddd82915adecdb1a901d" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7 + url: "https://pub.dev" + source: hosted + version: "3.1.1" vector_math: dependency: transitive description: @@ -546,4 +615,4 @@ packages: version: "3.1.2" sdks: dart: ">=3.3.1 <4.0.0" - flutter: ">=3.10.0" + flutter: ">=3.19.0" diff --git a/pubspec.yaml b/pubspec.yaml index 17c2345..314699e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,10 +40,11 @@ dependencies: path_provider: ^2.1.2 sqflite: ^2.3.2 encrypt: ^5.0.3 - marmiteur: ^3.0.0 flutter_launcher_icons: ^0.13.1 path: ^1.9.0 recipe_extractor: ^2.0.0 + url_launcher: ^6.2.5 + share: ^2.0.4 flutter_icons: