Skip to content

Commit

Permalink
improved recipes extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
judemont committed Apr 7, 2024
1 parent d1fd413 commit 59ca8b5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
48 changes: 23 additions & 25 deletions lib/widgets/extractRecipeButton.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:marmiteur/marmiteur.dart';

import 'package:recipe_extractor/recipe_extractor.dart';
import 'recipeEditorPage.dart';

class ExtractRecipeButton extends StatefulWidget {
Expand Down Expand Up @@ -39,31 +38,30 @@ class _ExtractRecipeButtonState extends State<ExtractRecipeButton> {
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
onPressed: () async {
String recipeUrl = recipeSiteUrlController.text;
marmiteur(recipeUrl).then((value) {
Navigator.pop(context, 'ok');
if (value["name"] == null) {
print("Failed to extract recipe");
SnackBar errorBar = const SnackBar(
content: Text("Failed to extract recipe"),
);
ScaffoldMessenger.of(context).showSnackBar(errorBar);
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RecipeEditorPage(
initialTitle: value["name"],
initialIngredients:
((value["recipeIngredients"]) ?? []).join("\n"),
initialSteps:
((value["recipeInstructions"]) ?? []).join("\n"),
),
RecipeData recipeData = await extractRecipe(recipeUrl);
Navigator.pop(context, 'ok');
if (recipeData.name == null) {
print("Failed to extract recipe");
SnackBar errorBar = const SnackBar(
content: Text("Failed to extract recipe"),
);
ScaffoldMessenger.of(context).showSnackBar(errorBar);
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RecipeEditorPage(
initialTitle: recipeData.name ?? "",
initialIngredients:
(recipeData.ingredients ?? []).join("\n"),
initialSteps:
(recipeData.instructions ?? []).join("\n"),
),
).then((value) => widget.reloadRecipes());
}
});
),
).then((value) => widget.reloadRecipes());
}
},
child: const Text('OK'),
),
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.7.4"
recipe_extractor:
dependency: "direct main"
description:
name: recipe_extractor
sha256: "54c260e464e82ea4e4c50d6e408b68939df7338205a6298b059001409456b671"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
marmiteur: ^3.0.0
flutter_launcher_icons: ^0.13.1
path: ^1.9.0
recipe_extractor: ^2.0.0


flutter_icons:
Expand Down

0 comments on commit 59ca8b5

Please sign in to comment.