diff --git a/lib/constants.dart b/lib/constants.dart new file mode 100644 index 0000000..61f0cc3 --- /dev/null +++ b/lib/constants.dart @@ -0,0 +1,16 @@ +import 'models/unit.dart'; + +Iterable units = [ + Unit('mg', UnitType.weight), + Unit('g', UnitType.weight), + Unit('kg', UnitType.weight), + Unit('ml', UnitType.fluid), + Unit('cl', UnitType.fluid), + Unit('dl', UnitType.fluid), + Unit('l', UnitType.fluid), + Unit('teaspoon', UnitType.fluid, system: System.imperial), + Unit('tablespoon', UnitType.fluid, system: System.imperial), + Unit('cup', UnitType.fluid, system: System.imperial), + Unit('pint', UnitType.fluid, system: System.imperial), + Unit('pieces', UnitType.count, system: System.neutral), +]; diff --git a/lib/models/ingredient.dart b/lib/models/ingredient.dart index a3d775e..27a1bfa 100644 --- a/lib/models/ingredient.dart +++ b/lib/models/ingredient.dart @@ -1,6 +1,8 @@ +import 'unit.dart'; + class Ingredient { final String title; - List possibleUnits = []; + List possibleUnits = []; List preferredBrands = []; Ingredient({ diff --git a/lib/models/unit.dart b/lib/models/unit.dart new file mode 100644 index 0000000..0ae76cf --- /dev/null +++ b/lib/models/unit.dart @@ -0,0 +1,17 @@ +class Unit { + final String name; + final UnitType type; + final System system; + + Unit(this.name, this.type, {this.system = System.metric}); +} + +enum System { metric, imperial, neutral } + +enum UnitType { + metric, + imperial, + fluid, + weight, + count, +} diff --git a/lib/pages/create_recipe_page.dart b/lib/pages/create_recipe_page.dart index 2a1b943..db8b7e4 100644 --- a/lib/pages/create_recipe_page.dart +++ b/lib/pages/create_recipe_page.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:rezepte/widgets/dropdown_textfield.dart'; -import 'package:rezepte/widgets/ingredients_list.dart'; +import '../widgets/ingredients_widget.dart'; import '../models/difficulty.dart'; import '../widgets/difficulty_dropdown.dart'; @@ -21,6 +20,7 @@ class _CreateRecipeState extends State { @override Widget build(BuildContext context) { + final width = MediaQuery.of(context).size.width; return Scaffold( appBar: AppBar( title: const Text('Create Recipe'), @@ -31,18 +31,19 @@ class _CreateRecipeState extends State { TextFormField( controller: titleText, decoration: const InputDecoration( - hintText: 'Title', + label: Text('Title'), ), ), TextFormField( controller: descriptionText, decoration: const InputDecoration( - hintText: 'Description', + label: Text('Description'), ), ), const DifficultyDropdown(), - const IngredientsList(), - const DropdownTextfield(), + IngredientsWidget( + width: width * 0.9, + ), ], ), ), diff --git a/lib/widgets/dropdown_textfield.dart b/lib/widgets/dropdown_textfield.dart deleted file mode 100644 index 68af1b3..0000000 --- a/lib/widgets/dropdown_textfield.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'package:flutter/material.dart'; - -class DropdownTextfield extends StatefulWidget { - const DropdownTextfield({super.key}); - - @override - State createState() => _DropdownTextfieldState(); -} - -class _DropdownTextfieldState extends State { - List get _getDropdownItems { - return [ - const DropdownMenuItem( - child: Text('rsitensroe'), - value: 1, - ), - const DropdownMenuItem( - child: Text('rstiersnmti'), - value: 2, - ) - ]; - } - - @override - Widget build(BuildContext context) { - final dropdownValue = _getDropdownItems.first.value; - return SizedBox( - width: 500, - child: TextField( - decoration: InputDecoration( - suffix: DropdownButton( - items: _getDropdownItems, - onChanged: _onDropdownChanged, - value: dropdownValue, - )), - ), - ); - } - - void _onDropdownChanged(value) {} -} diff --git a/lib/widgets/ingredients_widget.dart b/lib/widgets/ingredients_widget.dart new file mode 100644 index 0000000..681138b --- /dev/null +++ b/lib/widgets/ingredients_widget.dart @@ -0,0 +1,85 @@ +import 'package:flutter/material.dart'; +import '../constants.dart' as constants; + +class IngredientsWidget extends StatefulWidget { + const IngredientsWidget({super.key, this.width}); + + final double? width; + + @override + State createState() => _IngredientsWidgetState(); +} + +class _IngredientsWidgetState extends State { + late double width; + int itemCount = 1; + + Widget _ingredientListBuilder(BuildContext context, int index) { + if (index == itemCount) { + return FloatingActionButton( + onPressed: () => setState(() { + itemCount++; + }), + child: const Icon(Icons.add), + ); + } + return Row( + children: [ + SizedBox( + width: width * 0.6, + child: const TextField( + textInputAction: TextInputAction.next, + decoration: InputDecoration( + label: Text('Ingredient'), + ), + ), + ), + SizedBox( + width: width * 0.2, + child: const TextField( + maxLines: 1, + keyboardType: TextInputType.number, + textInputAction: TextInputAction.next, + decoration: InputDecoration( + label: Text('Amount'), + ), + ), + ), + SizedBox( + width: width * 0.2, + child: DropdownButtonFormField( + decoration: const InputDecoration( + label: Text('Unit'), + ), + isDense: true, + items: constants.units + .map( + (e) => DropdownMenuItem( + value: e.name, + child: SizedBox( + width: width * 0.135, + child: Text(e.name), + ), + ), + ) + .toList(), + onChanged: _onDropdownChanged, + ), + ) + ], + ); + } + + @override + Widget build(BuildContext context) { + width = widget.width ?? MediaQuery.of(context).size.width; + return Expanded( + child: ListView.builder( + itemCount: itemCount + 1, + itemBuilder: _ingredientListBuilder, + ), + ); + } + + void _onDropdownChanged(value) {} +}