refactoring
This commit is contained in:
@@ -22,11 +22,23 @@ final List<Unit> _fluid =
|
||||
constants.units.where((element) => element.type == UnitType.fluid).toList();
|
||||
|
||||
final List<Ingredient> exampleIngredients = [
|
||||
Ingredient(title: 'Karotte', possibleUnits: _weightAndCount),
|
||||
Ingredient(title: 'Kartoffel', possibleUnits: _weightAndCount),
|
||||
Ingredient(title: 'Kaffeebohnen', possibleUnits: _weight),
|
||||
Ingredient(title: 'Milch', possibleUnits: _fluid),
|
||||
Ingredient(title: 'Limettenblätter', possibleUnits: _count),
|
||||
Ingredient(
|
||||
title: 'Karotte',
|
||||
possibleUnits: _weightAndCount,
|
||||
type: IngredientType.vegetable),
|
||||
Ingredient(
|
||||
title: 'Kartoffel',
|
||||
possibleUnits: _weightAndCount,
|
||||
type: IngredientType.vegetable),
|
||||
Ingredient(
|
||||
title: 'Kaffeebohnen',
|
||||
possibleUnits: _weight,
|
||||
type: IngredientType.other),
|
||||
Ingredient(title: 'Milch', possibleUnits: _fluid, type: IngredientType.dairy),
|
||||
Ingredient(
|
||||
title: 'Limettenblätter',
|
||||
possibleUnits: _count,
|
||||
type: IngredientType.other),
|
||||
];
|
||||
|
||||
final List<Recipe> exampleRecipes = [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:rezepte/pages/create_recipe_page.dart';
|
||||
import 'package:rezepte/pages/create_recipe/create_recipe_page.dart';
|
||||
import 'package:rezepte/pages/dashboard_page.dart';
|
||||
import 'package:rezepte/services/providers/recipe_list_provider.dart';
|
||||
import 'package:rezepte/services/providers/recipe_provider.dart';
|
||||
|
||||
@@ -9,21 +9,25 @@ class Ingredient {
|
||||
final String title;
|
||||
List<Unit> possibleUnits;
|
||||
List<String> preferredBrands;
|
||||
IngredientType type;
|
||||
|
||||
Ingredient({
|
||||
required this.title,
|
||||
required this.type,
|
||||
this.possibleUnits = const [],
|
||||
this.preferredBrands = const [],
|
||||
});
|
||||
|
||||
factory Ingredient.fromJson(Map<String, dynamic> json) => Ingredient(
|
||||
title: json['title'] as String,
|
||||
type: json['ingredient_type'] as IngredientType,
|
||||
possibleUnits: _unitsFromJson(json['possibleUnits']),
|
||||
preferredBrands: json['preferredBrands'] as List<String>,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'title': title,
|
||||
'ingredient_type': type,
|
||||
'possibleUnits': possibleUnits.map((e) => e.toJson()).toList(),
|
||||
'preferredBrands': preferredBrands,
|
||||
};
|
||||
@@ -42,3 +46,15 @@ class Ingredient {
|
||||
static List<Unit> _unitsFromJson(List<Map<String, dynamic>> jsonList) =>
|
||||
jsonList.map((e) => Unit.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
enum IngredientType {
|
||||
vegetable,
|
||||
meat,
|
||||
fish,
|
||||
grain,
|
||||
fruit,
|
||||
dairy,
|
||||
fatsAndOil,
|
||||
spice,
|
||||
other,
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'package:provider/provider.dart';
|
||||
import 'package:rezepte/services/providers/db/dbhelper.dart';
|
||||
import 'package:rezepte/widgets/ingredients_bottomsheet.dart';
|
||||
import 'package:rezepte/widgets/will_pop_scope.dart';
|
||||
import '../models/difficulty.dart';
|
||||
import '../models/ingredient_list_entry.dart';
|
||||
import '../models/recipe.dart';
|
||||
import '../services/providers/recipe_list_provider.dart';
|
||||
import '../services/providers/recipe_provider.dart';
|
||||
import '../../models/difficulty.dart';
|
||||
import '../../models/ingredient_list_entry.dart';
|
||||
import '../../models/recipe.dart';
|
||||
import '../../services/providers/recipe_list_provider.dart';
|
||||
import '../../services/providers/recipe_provider.dart';
|
||||
|
||||
class CreateRecipe extends StatefulWidget {
|
||||
const CreateRecipe({super.key});
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rezepte/pages/create_recipe_page.dart';
|
||||
import 'package:rezepte/pages/create_recipe/create_recipe_page.dart';
|
||||
import 'package:rezepte/widgets/recipe_list.dart';
|
||||
|
||||
class Dashboard extends StatelessWidget {
|
||||
|
||||
@@ -169,7 +169,8 @@ class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> {
|
||||
}
|
||||
|
||||
bool _submit() {
|
||||
final ingredient = Ingredient(title: _ingredientController.text);
|
||||
final ingredient = Ingredient(
|
||||
title: _ingredientController.text, type: IngredientType.other);
|
||||
final unit = selectedUnit;
|
||||
final amount = int.tryParse(_amountController.text);
|
||||
if (ingredient.title.isEmpty || unit == null || amount == null) {
|
||||
|
||||
Reference in New Issue
Block a user