changed ingredient input

This commit is contained in:
SomnusVeritas
2023-10-17 16:37:39 +02:00
parent 263fe00407
commit 16bf7e4cbc
3 changed files with 126 additions and 61 deletions

View File

@@ -44,7 +44,10 @@ class _CreateRecipeState extends State<CreateRecipe> {
DifficultyDropdown( DifficultyDropdown(
onChanged: _onChanged, onChanged: _onChanged,
), ),
FloatingActionButton(onPressed: _openIngredientBottomSheet), ElevatedButton(
onPressed: _openIngredientBottomSheet,
child: const Text('Add Ingredient'),
),
], ],
), ),
), ),

View File

@@ -10,21 +10,20 @@ class DifficultyDropdown extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
List<DropdownMenuEntry> dropdownMenuEntryList = DifficultyUtil.difficulties List<DropdownMenuEntry<Difficulty>> dropdownMenuEntryList =
.map((e) => Difficulty.values.map((e) => _toDropdownMenuEntry(e, e.name)).toList();
_toDropdownMenuEntry(DifficultyUtil.difficulties.indexOf(e), e))
.toList();
return DropdownMenu( return DropdownMenu<Difficulty?>(
dropdownMenuEntries: dropdownMenuEntryList, dropdownMenuEntries: dropdownMenuEntryList,
onSelected: (value) { onSelected: (value) {
if (onChanged != null) { if (onChanged != null) {
onChanged!(value as int); onChanged!(value?.index ?? -1);
} }
}, },
); );
} }
DropdownMenuEntry _toDropdownMenuEntry(int index, String text) => DropdownMenuEntry<Difficulty> _toDropdownMenuEntry(
DropdownMenuEntry(value: index, label: text); Difficulty difficulty, String text) =>
DropdownMenuEntry(value: difficulty, label: text);
} }

View File

@@ -12,17 +12,14 @@ class IngredientsBottomsheet extends StatefulWidget {
} }
class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> { class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> {
TextEditingController dropdownController = TextEditingController();
final List<DropdownMenuEntry<Unit>> unitEntries = [];
final List<DropdownMenuEntry<Ingredient>> ingredientEntries = []; final List<DropdownMenuEntry<Ingredient>> ingredientEntries = [];
final List<DropdownMenuEntry<Unit>> unitEntries = [];
Unit? selectedUnit; Unit? selectedUnit;
@override
Widget build(BuildContext context) { bool _isOptional = false;
return BottomSheet( TextEditingController _ingredientController = TextEditingController();
onClosing: onClosing, TextEditingController _amountController = TextEditingController();
builder: _bottomSheetContent, TextEditingController _unitController = TextEditingController();
);
}
@override @override
void initState() { void initState() {
@@ -39,56 +36,122 @@ class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> {
void onClosing() {} void onClosing() {}
Widget _bottomSheetContent(BuildContext context) { Widget _bottomSheetContent(BuildContext context) {
return Padding( return Wrap(
padding: EdgeInsets.only( children: [
top: 20, Padding(
left: 10, padding: EdgeInsets.only(
right: 10, top: 20,
bottom: MediaQuery.of(context).viewInsets.bottom, left: 20,
), right: 20,
child: Column( bottom: MediaQuery.of(context).viewInsets.bottom,
children: [ ),
Row( child: Column(
mainAxisSize: MainAxisSize.max,
children: [ children: [
Expanded( DropdownMenu<Ingredient?>(
flex: 4, dropdownMenuEntries: ingredientEntries,
child: DropdownMenu<Ingredient>( enableSearch: true,
dropdownMenuEntries: ingredientEntries, enableFilter: true,
enableSearch: true, requestFocusOnTap: true,
enableFilter: true, controller: _ingredientController,
requestFocusOnTap: true, 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<Unit?>(
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: [ children: [
Expanded( TextButton(
child: TextField( onPressed: _cancelTapped,
maxLines: 1, child: const Text('Cancel'),
onTapOutside: (_) => ),
FocusManager.instance.primaryFocus?.unfocus(), TextButton(
keyboardType: TextInputType.number, onPressed: _finishTapped,
textInputAction: TextInputAction.next, child: const Text('Finish'),
decoration: InputDecoration( ),
label: Text('Amount'), TextButton(
), onPressed: _nextTapped,
), child: const Text('Next'),
), ),
DropdownMenu<Unit>(
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() {}
} }