diff --git a/lib/pages/create_recipe_page.dart b/lib/pages/create_recipe_page.dart index a1b5355..6d5e389 100644 --- a/lib/pages/create_recipe_page.dart +++ b/lib/pages/create_recipe_page.dart @@ -44,7 +44,10 @@ class _CreateRecipeState extends State { DifficultyDropdown( onChanged: _onChanged, ), - FloatingActionButton(onPressed: _openIngredientBottomSheet), + ElevatedButton( + onPressed: _openIngredientBottomSheet, + child: const Text('Add Ingredient'), + ), ], ), ), diff --git a/lib/widgets/difficulty_dropdown.dart b/lib/widgets/difficulty_dropdown.dart index aa1bbfa..6db4686 100644 --- a/lib/widgets/difficulty_dropdown.dart +++ b/lib/widgets/difficulty_dropdown.dart @@ -10,21 +10,20 @@ class DifficultyDropdown extends StatelessWidget { @override Widget build(BuildContext context) { - List dropdownMenuEntryList = DifficultyUtil.difficulties - .map((e) => - _toDropdownMenuEntry(DifficultyUtil.difficulties.indexOf(e), e)) - .toList(); + List> dropdownMenuEntryList = + Difficulty.values.map((e) => _toDropdownMenuEntry(e, e.name)).toList(); - return DropdownMenu( + return DropdownMenu( dropdownMenuEntries: dropdownMenuEntryList, onSelected: (value) { if (onChanged != null) { - onChanged!(value as int); + onChanged!(value?.index ?? -1); } }, ); } - DropdownMenuEntry _toDropdownMenuEntry(int index, String text) => - DropdownMenuEntry(value: index, label: text); + DropdownMenuEntry _toDropdownMenuEntry( + Difficulty difficulty, String text) => + DropdownMenuEntry(value: difficulty, label: text); } diff --git a/lib/widgets/ingredients_bottomsheet.dart b/lib/widgets/ingredients_bottomsheet.dart index a313a31..47e8746 100644 --- a/lib/widgets/ingredients_bottomsheet.dart +++ b/lib/widgets/ingredients_bottomsheet.dart @@ -12,17 +12,14 @@ class IngredientsBottomsheet extends StatefulWidget { } class _IngredientsBottomsheetState extends State { - TextEditingController dropdownController = TextEditingController(); - final List> unitEntries = []; final List> ingredientEntries = []; + final List> unitEntries = []; Unit? selectedUnit; - @override - Widget build(BuildContext context) { - return BottomSheet( - onClosing: onClosing, - builder: _bottomSheetContent, - ); - } + + bool _isOptional = false; + TextEditingController _ingredientController = TextEditingController(); + TextEditingController _amountController = TextEditingController(); + TextEditingController _unitController = TextEditingController(); @override void initState() { @@ -39,56 +36,122 @@ class _IngredientsBottomsheetState extends State { 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( + return Wrap( + children: [ + Padding( + padding: EdgeInsets.only( + top: 20, + left: 20, + right: 20, + bottom: MediaQuery.of(context).viewInsets.bottom, + ), + child: Column( + mainAxisSize: MainAxisSize.max, children: [ - Expanded( - flex: 4, - child: DropdownMenu( - dropdownMenuEntries: ingredientEntries, - enableSearch: true, - enableFilter: true, - requestFocusOnTap: true, - ), + DropdownMenu( + dropdownMenuEntries: ingredientEntries, + enableSearch: true, + enableFilter: true, + requestFocusOnTap: true, + controller: _ingredientController, + label: const Text('Ingredient'), + textStyle: + TextStyle(color: Theme.of(context).colorScheme.onSurface), + ), + Row( + children: [ + Expanded( + child: TextField( + maxLines: 1, + controller: _amountController, + onTapOutside: (_) => + FocusManager.instance.primaryFocus?.unfocus(), + keyboardType: TextInputType.number, + textInputAction: TextInputAction.next, + decoration: const InputDecoration( + label: Text('Amount'), + ), + style: TextStyle( + color: Theme.of(context).colorScheme.onSurface), + ), + ), + DropdownMenu( + label: const Text('Unit'), + width: 150, + requestFocusOnTap: true, + controller: _unitController, + dropdownMenuEntries: unitEntries, + onSelected: (unit) => setState(() { + selectedUnit = unit; + }), + textStyle: TextStyle( + color: Theme.of(context).colorScheme.onSurface), + ), + ], + ), + Row( + children: [ + Text( + 'optional', + style: TextStyle( + color: Theme.of(context).colorScheme.onSurface), + ), + Checkbox( + value: _isOptional, + onChanged: (_) => + setState(() => _isOptional = !_isOptional), + ), + ], ), ], ), - Row( + ), + const SizedBox( + height: 200, + width: 400, + ), + Padding( + padding: const EdgeInsets.all(10), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, children: [ - Expanded( - child: TextField( - maxLines: 1, - onTapOutside: (_) => - FocusManager.instance.primaryFocus?.unfocus(), - keyboardType: TextInputType.number, - textInputAction: TextInputAction.next, - decoration: InputDecoration( - label: Text('Amount'), - ), - ), + TextButton( + onPressed: _cancelTapped, + child: const Text('Cancel'), + ), + TextButton( + onPressed: _finishTapped, + child: const Text('Finish'), + ), + TextButton( + onPressed: _nextTapped, + child: const Text('Next'), ), - DropdownMenu( - label: const Text('Unit'), - width: 150, - requestFocusOnTap: true, - controller: dropdownController, - dropdownMenuEntries: unitEntries, - onSelected: (unit) => setState(() { - selectedUnit = unit; - }), - ) ], - ) - ], - ), + ), + ), + ], ); } + + @override + Widget build(BuildContext context) { + return BottomSheet( + onClosing: onClosing, + builder: _bottomSheetContent, + ); + } + + void _nextTapped() { + setState(() { + _ingredientController.value = TextEditingValue.empty; + _unitController.value = TextEditingValue.empty; + _amountController.value = TextEditingValue.empty; + _isOptional = false; + }); + } + + void _finishTapped() {} + + void _cancelTapped() {} }