diff --git a/.github/workflows/flutter-build-apk.yml b/.github/workflows/flutter-build-apk.yml index 1f80334..b71661f 100644 --- a/.github/workflows/flutter-build-apk.yml +++ b/.github/workflows/flutter-build-apk.yml @@ -76,30 +76,3 @@ jobs: with: name: release-apk path: build/app/outputs/apk/release/app-release.apk - - - name: create-release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITUB_TOKEN }} - with: - tag_name: v${{ steps.version.outputs.version }} - release_name: Release ${{ steps.version.outputs.version }} - draft: true - prerelease: false - - - name: Upload release asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ${{steps.sign_app.outputs.signedFile}} - asset_name: reciper-release-${{ steps.version.outputs.version }}.apk - asset_content_type: application/apk - - name: Publish release - uses: eregon/publish-release@v1.0.6 - env: - GITHUB_TOKEN: ${{ secrets.GITUB_TOKEN }} - with: - release_id: ${{ steps.create_release.outputs.id }} \ No newline at end of file diff --git a/lib/database.dart b/lib/database.dart index fd50f27..e52650c 100644 --- a/lib/database.dart +++ b/lib/database.dart @@ -11,7 +11,7 @@ class DatabaseService { static const String databaseName = "reciperDB.sqlite"; static Database? db; - static const DATABASE_VERSION = 1; + static const DATABASE_VERSION = 2; List tables = ["Recipes"]; static const SECRET_KEY = "2023_PRIVATE_KEY_ENCRYPT_2023"; @@ -28,9 +28,11 @@ class DatabaseService { await createTables(db); }, onUpgrade: (db, oldVersion, newVersion) async { + print("UPDATE DB"); await updateTables(db, oldVersion, newVersion); }, onOpen: (db) async { + print("OPEN DB"); await openDB(db); }, ); @@ -45,6 +47,12 @@ class DatabaseService { static updateTables(Database db, int oldVersion, int newVersion) { print(" DB Version : $newVersion"); + print(oldVersion); + if (oldVersion < newVersion) { + if (oldVersion < 3) { + db.execute("""ALTER TABLE Recipes ADD COLUMN servings TEXT """); + } + } } static Future createTables(Database database) async { @@ -53,6 +61,7 @@ class DatabaseService { id INTEGER PRIMARY KEY AUTOINCREMENT, steps TEXT, title TEXT NOT NULL, + servings TEXT, ingredients TEXT ) """); @@ -74,8 +83,9 @@ class DatabaseService { static Future> getRecipes({String searchQuery = ""}) async { final db = await DatabaseService.initializeDb(); - final List> queryResult = + final List> queryResult = await db.query('Recipes', where: "title LIKE '%$searchQuery%'"); + print(queryResult); return queryResult.map((e) => Recipe.fromMap(e)).toList(); } diff --git a/lib/models/recipe.dart b/lib/models/recipe.dart index 728d98d..bed1783 100644 --- a/lib/models/recipe.dart +++ b/lib/models/recipe.dart @@ -1,26 +1,34 @@ class Recipe { int? id; String steps; + String servings; String title; String ingredients; - Recipe({this.id, this.steps = "", this.title = '', this.ingredients = ""}); + Recipe( + {this.id, + this.steps = "", + this.servings = "", + this.title = '', + this.ingredients = ""}); Map toMap() { return { 'id': id, + 'servings': servings, 'steps': steps, 'title': title, 'ingredients': ingredients, }; } - static Recipe fromMap(Map map) { + static Recipe fromMap(Map map) { return Recipe( - id: map['id'] as int, - steps: map['steps'] as String, - title: map['title'] as String, - ingredients: map['ingredients'] as String, + id: map['id'] as int?, + servings: map["servings"] ?? "", + steps: map['steps'] ?? "", + title: map['title'] ?? "", + ingredients: map['ingredients'] ?? "", ); } } diff --git a/lib/widgets/extractRecipeButton.dart b/lib/widgets/extractRecipeButton.dart index 70f2a6a..36619f4 100644 --- a/lib/widgets/extractRecipeButton.dart +++ b/lib/widgets/extractRecipeButton.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:recipe_extractor/recipe_extractor.dart'; +import 'package:reciper/models/recipe.dart'; import 'recipeEditorPage.dart'; class ExtractRecipeButton extends StatefulWidget { @@ -53,11 +54,13 @@ class _ExtractRecipeButtonState extends State { context, MaterialPageRoute( builder: (context) => RecipeEditorPage( - initialTitle: recipeData.name ?? "", - initialIngredients: - (recipeData.ingredients ?? []).join("\n"), - initialSteps: - (recipeData.instructions ?? []).join("\n"), + initialRecipe: Recipe( + title: recipeData.name ?? "", + servings: recipeData.servings ?? "", + ingredients: + (recipeData.ingredients ?? []).join("\n"), + steps: (recipeData.instructions ?? []).join("\n"), + ), ), ), ).then((value) => widget.reloadRecipes()); diff --git a/lib/widgets/recipeEditorPage.dart b/lib/widgets/recipeEditorPage.dart index 4e48137..7f77f79 100644 --- a/lib/widgets/recipeEditorPage.dart +++ b/lib/widgets/recipeEditorPage.dart @@ -4,16 +4,12 @@ import 'package:reciper/models/recipe.dart'; import 'package:reciper/widgets/homePage.dart'; class RecipeEditorPage extends StatefulWidget { - final String initialTitle; - final String initialIngredients; - final String initialSteps; - final int? recipeID; - const RecipeEditorPage( - {super.key, - this.initialTitle = "", - this.initialIngredients = "", - this.initialSteps = "", - this.recipeID}); + // final String initialTitle; + // final String initialIngredients; + // final String initialSteps; + // final int? recipeID; + final Recipe? initialRecipe; + const RecipeEditorPage({super.key, this.initialRecipe}); @override State createState() => _RecipeEditorPageState(); @@ -25,6 +21,7 @@ class _RecipeEditorPageState extends State { String title = ""; String ingredients = ""; String steps = ""; + String servings = ""; @override Widget build(BuildContext context) { @@ -38,16 +35,18 @@ class _RecipeEditorPageState extends State { onPressed: () { if (formKey.currentState!.validate()) { formKey.currentState!.save(); - if (widget.recipeID == null) { + if (widget.initialRecipe == null) { print("NEW RECIPE"); DatabaseService.createRecipe(Recipe( title: title, + servings: servings, steps: steps, ingredients: ingredients)); } else { print("RECIPE UPDATE"); DatabaseService.updateRecipe(Recipe( - id: widget.recipeID, + id: widget.initialRecipe!.id, + servings: servings, title: title, steps: steps, ingredients: ingredients)); @@ -69,7 +68,7 @@ class _RecipeEditorPageState extends State { child: Column( children: [ TextFormField( - initialValue: widget.initialTitle, + initialValue: widget.initialRecipe?.title, validator: (value) { if (value!.isEmpty) { return 'Please enter something.'; @@ -86,7 +85,18 @@ class _RecipeEditorPageState extends State { ), SizedBox(height: fieldsMargin), TextFormField( - initialValue: widget.initialIngredients, + initialValue: widget.initialRecipe?.servings, + onSaved: (value) { + servings = value!; + }, + decoration: const InputDecoration( + border: OutlineInputBorder(), + hintText: 'Servings', + ), + ), + SizedBox(height: fieldsMargin), + TextFormField( + initialValue: widget.initialRecipe?.ingredients, validator: (value) { if (value!.isEmpty) { return 'Please enter something.'; @@ -105,7 +115,7 @@ class _RecipeEditorPageState extends State { ), SizedBox(height: fieldsMargin), TextFormField( - initialValue: widget.initialSteps, + initialValue: widget.initialRecipe?.steps, validator: (value) { if (value!.isEmpty) { return 'Please enter something.'; diff --git a/lib/widgets/recipeViewPage.dart b/lib/widgets/recipeViewPage.dart index 923f16f..e357aee 100644 --- a/lib/widgets/recipeViewPage.dart +++ b/lib/widgets/recipeViewPage.dart @@ -41,10 +41,7 @@ class _RecipeViewPageState extends State { .push( MaterialPageRoute( builder: (context) => RecipeEditorPage( - initialTitle: widget.recipe.title, - initialIngredients: widget.recipe.ingredients, - initialSteps: widget.recipe.steps, - recipeID: widget.recipe.id, + initialRecipe: widget.recipe, )), ) .then((value) => widget.reloadRecipes()); @@ -66,6 +63,12 @@ class _RecipeViewPageState extends State { const SizedBox( height: 15, ), + Text(widget.recipe.servings.isNotEmpty + ? "Servings: ${widget.recipe.servings}" + : ""), + const SizedBox( + height: 15, + ), const Text( "Ingredients :", style: diff --git a/lib/widgets/recipesListView.dart b/lib/widgets/recipesListView.dart index 94ca8be..eeaf2d5 100644 --- a/lib/widgets/recipesListView.dart +++ b/lib/widgets/recipesListView.dart @@ -29,7 +29,7 @@ class _RecipeListViewState extends State { itemCount: widget.recipes.length, itemBuilder: (BuildContext context, int index) { return ListTile( - title: Text(widget.recipes[index].title), + title: Text(widget.recipes[index].title ?? ""), selected: selectedRecipesID.contains(widget.recipes[index].id), selectedColor: Colors.white, selectedTileColor: const Color.fromARGB(255, 63, 63, 63), diff --git a/pubspec.lock b/pubspec.lock index 4a026d4..d5cb5e8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -204,10 +204,10 @@ packages: dependency: transitive description: name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "0.7.1" json_annotation: dependency: transitive description: @@ -364,18 +364,18 @@ packages: dependency: transitive description: name: pointycastle - sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29" + sha256: "70fe966348fe08c34bf929582f1d8247d9d9408130723206472b4687227e4333" url: "https://pub.dev" source: hosted - version: "3.7.4" + version: "3.8.0" recipe_extractor: dependency: "direct main" description: name: recipe_extractor - sha256: "54c260e464e82ea4e4c50d6e408b68939df7338205a6298b059001409456b671" + sha256: "5fe7498b8cc098c6f72cd8cdd94a84047bfc01fb3d3f33b50760ab582b455b85" url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "2.1.0" share: dependency: "direct main" description: @@ -401,10 +401,10 @@ packages: dependency: "direct main" description: name: sqflite - sha256: a9016f495c927cb90557c909ff26a6d92d9bd54fc42ba92e19d4e79d61e798c6 + sha256: "5ce2e1a15e822c3b4bfb5400455775e421da7098eed8adc8f26298ada7c9308c" url: "https://pub.dev" source: hosted - version: "2.3.2" + version: "2.3.3" sqflite_common: dependency: transitive description: @@ -425,10 +425,10 @@ packages: dependency: transitive description: name: sqlite3 - sha256: "072128763f1547e3e9b4735ce846bfd226d68019ccda54db4cd427b12dfdedc9" + sha256: "1abbeb84bf2b1a10e5e1138c913123c8aa9d83cd64e5f9a0dd847b3c83063202" url: "https://pub.dev" source: hosted - version: "2.4.0" + version: "2.4.2" sqlite3_flutter_libs: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 314699e..252b3d8 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: 0.0.17+1 +version: 1.0.0+2 environment: sdk: '>=3.3.1 <4.0.0'