changed up the way that ingredients can be added
This commit is contained in:
27
lib/example_data.dart
Normal file
27
lib/example_data.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:rezepte/models/unit.dart';
|
||||
|
||||
import 'models/ingredient.dart';
|
||||
import 'constants.dart' as constants;
|
||||
|
||||
final List<Unit> _weightAndCount = constants.units
|
||||
.where((element) =>
|
||||
element.type == UnitType.weight || element.type == UnitType.count)
|
||||
.toList();
|
||||
|
||||
final List<Unit> _weight = constants.units
|
||||
.where((element) => element.type == UnitType.weight)
|
||||
.toList();
|
||||
|
||||
final List<Unit> _count =
|
||||
constants.units.where((element) => element.type == UnitType.count).toList();
|
||||
|
||||
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),
|
||||
];
|
||||
@@ -2,12 +2,12 @@ import 'unit.dart';
|
||||
|
||||
class Ingredient {
|
||||
final String title;
|
||||
List<Unit> possibleUnits = [];
|
||||
List<String> preferredBrands = [];
|
||||
List<Unit> possibleUnits;
|
||||
List<String> preferredBrands;
|
||||
|
||||
Ingredient({
|
||||
required this.title,
|
||||
required this.possibleUnits,
|
||||
required this.preferredBrands,
|
||||
this.preferredBrands = const [],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ class Unit {
|
||||
enum System { metric, imperial, neutral }
|
||||
|
||||
enum UnitType {
|
||||
metric,
|
||||
imperial,
|
||||
fluid,
|
||||
weight,
|
||||
count,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rezepte/widgets/ingredients_bottomsheet.dart';
|
||||
import '../widgets/ingredients_widget.dart';
|
||||
|
||||
import '../models/difficulty.dart';
|
||||
@@ -43,9 +44,7 @@ class _CreateRecipeState extends State<CreateRecipe> {
|
||||
DifficultyDropdown(
|
||||
onChanged: _onChanged,
|
||||
),
|
||||
IngredientsWidget(
|
||||
width: width * 0.9,
|
||||
),
|
||||
FloatingActionButton(onPressed: _openIngredientBottomSheet),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -55,4 +54,11 @@ class _CreateRecipeState extends State<CreateRecipe> {
|
||||
void _onChanged(int index) {
|
||||
_recipeDifficulty = Difficulty.values.elementAt(index);
|
||||
}
|
||||
|
||||
void _openIngredientBottomSheet() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) => const IngredientsBottomsheet(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
94
lib/widgets/ingredients_bottomsheet.dart
Normal file
94
lib/widgets/ingredients_bottomsheet.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../constants.dart' as constants;
|
||||
import '../models/ingredient.dart';
|
||||
import '../models/unit.dart';
|
||||
import '../example_data.dart' as ea;
|
||||
|
||||
class IngredientsBottomsheet extends StatefulWidget {
|
||||
const IngredientsBottomsheet({super.key});
|
||||
|
||||
@override
|
||||
State<IngredientsBottomsheet> createState() => _IngredientsBottomsheetState();
|
||||
}
|
||||
|
||||
class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> {
|
||||
TextEditingController dropdownController = TextEditingController();
|
||||
final List<DropdownMenuEntry<Unit>> unitEntries = [];
|
||||
final List<DropdownMenuEntry<Ingredient>> ingredientEntries = [];
|
||||
Unit? selectedUnit;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BottomSheet(
|
||||
onClosing: onClosing,
|
||||
builder: _bottomSheetContent,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
for (var unit in constants.units) {
|
||||
unitEntries.add(DropdownMenuEntry(value: unit, label: unit.name));
|
||||
}
|
||||
for (var ingredient in ea.exampleIngredients) {
|
||||
ingredientEntries
|
||||
.add(DropdownMenuEntry(value: ingredient, label: ingredient.title));
|
||||
}
|
||||
}
|
||||
|
||||
void onClosing() {}
|
||||
|
||||
Widget _bottomSheetContent(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: 20,
|
||||
left: 10,
|
||||
right: 10,
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: DropdownMenu<Ingredient>(
|
||||
dropdownMenuEntries: ingredientEntries,
|
||||
enableSearch: true,
|
||||
enableFilter: true,
|
||||
requestFocusOnTap: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
maxLines: 1,
|
||||
onTapOutside: (_) =>
|
||||
FocusManager.instance.primaryFocus?.unfocus(),
|
||||
keyboardType: TextInputType.number,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
label: Text('Amount'),
|
||||
),
|
||||
),
|
||||
),
|
||||
DropdownMenu<Unit>(
|
||||
label: const Text('Unit'),
|
||||
width: 150,
|
||||
requestFocusOnTap: true,
|
||||
controller: dropdownController,
|
||||
dropdownMenuEntries: unitEntries,
|
||||
onSelected: (unit) => setState(() {
|
||||
selectedUnit = unit;
|
||||
}),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user