Skip to content

Commit

Permalink
added servings
Browse files Browse the repository at this point in the history
  • Loading branch information
judemont committed Apr 8, 2024
1 parent 826c929 commit a06eb9b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 71 deletions.
27 changes: 0 additions & 27 deletions .github/workflows/flutter-build-apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITUB_TOKEN }}
with:
release_id: ${{ steps.create_release.outputs.id }}
14 changes: 12 additions & 2 deletions lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> tables = ["Recipes"];

static const SECRET_KEY = "2023_PRIVATE_KEY_ENCRYPT_2023";
Expand All @@ -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);
},
);
Expand All @@ -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<void> createTables(Database database) async {
Expand All @@ -53,6 +61,7 @@ class DatabaseService {
id INTEGER PRIMARY KEY AUTOINCREMENT,
steps TEXT,
title TEXT NOT NULL,
servings TEXT,
ingredients TEXT
)
""");
Expand All @@ -74,8 +83,9 @@ class DatabaseService {
static Future<List<Recipe>> getRecipes({String searchQuery = ""}) async {
final db = await DatabaseService.initializeDb();

final List<Map<String, Object?>> queryResult =
final List<Map<String, dynamic>> queryResult =
await db.query('Recipes', where: "title LIKE '%$searchQuery%'");
print(queryResult);
return queryResult.map((e) => Recipe.fromMap(e)).toList();
}

Expand Down
20 changes: 14 additions & 6 deletions lib/models/recipe.dart
Original file line number Diff line number Diff line change
@@ -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<String, Object?> toMap() {
return {
'id': id,
'servings': servings,
'steps': steps,
'title': title,
'ingredients': ingredients,
};
}

static Recipe fromMap(Map<String, Object?> map) {
static Recipe fromMap(Map<String, dynamic> 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'] ?? "",
);
}
}
13 changes: 8 additions & 5 deletions lib/widgets/extractRecipeButton.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -53,11 +54,13 @@ class _ExtractRecipeButtonState extends State<ExtractRecipeButton> {
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());
Expand Down
40 changes: 25 additions & 15 deletions lib/widgets/recipeEditorPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecipeEditorPage> createState() => _RecipeEditorPageState();
Expand All @@ -25,6 +21,7 @@ class _RecipeEditorPageState extends State<RecipeEditorPage> {
String title = "";
String ingredients = "";
String steps = "";
String servings = "";

@override
Widget build(BuildContext context) {
Expand All @@ -38,16 +35,18 @@ class _RecipeEditorPageState extends State<RecipeEditorPage> {
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));
Expand All @@ -69,7 +68,7 @@ class _RecipeEditorPageState extends State<RecipeEditorPage> {
child: Column(
children: [
TextFormField(
initialValue: widget.initialTitle,
initialValue: widget.initialRecipe?.title,
validator: (value) {
if (value!.isEmpty) {
return 'Please enter something.';
Expand All @@ -86,7 +85,18 @@ class _RecipeEditorPageState extends State<RecipeEditorPage> {
),
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.';
Expand All @@ -105,7 +115,7 @@ class _RecipeEditorPageState extends State<RecipeEditorPage> {
),
SizedBox(height: fieldsMargin),
TextFormField(
initialValue: widget.initialSteps,
initialValue: widget.initialRecipe?.steps,
validator: (value) {
if (value!.isEmpty) {
return 'Please enter something.';
Expand Down
11 changes: 7 additions & 4 deletions lib/widgets/recipeViewPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ class _RecipeViewPageState extends State<RecipeViewPage> {
.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());
Expand All @@ -66,6 +63,12 @@ class _RecipeViewPageState extends State<RecipeViewPage> {
const SizedBox(
height: 15,
),
Text(widget.recipe.servings.isNotEmpty
? "Servings: ${widget.recipe.servings}"
: ""),
const SizedBox(
height: 15,
),
const Text(
"Ingredients :",
style:
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/recipesListView.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _RecipeListViewState extends State<RecipeListView> {
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),
Expand Down
20 changes: 10 additions & 10 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit a06eb9b

Please sign in to comment.