Skip to content

Commit

Permalink
back homepage after recipe update
Browse files Browse the repository at this point in the history
  • Loading branch information
judemont committed Apr 8, 2024
1 parent 68cf471 commit 996abd1
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 26 deletions.
33 changes: 26 additions & 7 deletions lib/widgets/homePage.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -30,14 +32,14 @@ class _HomePageState extends State<HomePage> {
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: () {
Expand All @@ -56,6 +58,11 @@ class _HomePageState extends State<HomePage> {
NewRecipeButton(reloadRecipes: loadRecipes),
],
),
drawer: Drawer(
child: Settings(
backup: backup,
restore: restore,
)),
body: Column(
children: [
Visibility(
Expand Down Expand Up @@ -106,4 +113,16 @@ class _HomePageState extends State<HomePage> {
selectedRecipes = [];
});
}

Future<void> backup() async {
DatabaseService db = DatabaseService();
db.generateBackup().then((String result) {
Share.share(result);
});
}

Future<void> restore(String backup) async {
DatabaseService db = DatabaseService();
db.restoreBackup(backup);
}
}
6 changes: 5 additions & 1 deletion lib/widgets/recipeEditorPage.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -51,7 +52,10 @@ class _RecipeEditorPageState extends State<RecipeEditorPage> {
steps: steps,
ingredients: ingredients));
}
Navigator.pop(context);

Navigator.of(context).push(
MaterialPageRoute(builder: (context) => HomePage()),
);
}
},
icon: const Icon(Icons.check))
Expand Down
142 changes: 142 additions & 0 deletions lib/widgets/settings.dart
Original file line number Diff line number Diff line change
@@ -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<Settings> createState() => _SettingsState();
}

class _SettingsState extends State<Settings> {
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')),
)
],
),
),
),
],
),
),
);
}
}
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#include "generated_plugin_registrant.h"

#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

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);
}
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
sqlite3_flutter_libs
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
103 changes: 86 additions & 17 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Loading

0 comments on commit 996abd1

Please sign in to comment.