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(
onChanged: _onChanged,
),
FloatingActionButton(onPressed: _openIngredientBottomSheet),
ElevatedButton(
onPressed: _openIngredientBottomSheet,
child: const Text('Add Ingredient'),
),
],
),
),

View File

@@ -10,21 +10,20 @@ class DifficultyDropdown extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<DropdownMenuEntry> dropdownMenuEntryList = DifficultyUtil.difficulties
.map((e) =>
_toDropdownMenuEntry(DifficultyUtil.difficulties.indexOf(e), e))
.toList();
List<DropdownMenuEntry<Difficulty>> dropdownMenuEntryList =
Difficulty.values.map((e) => _toDropdownMenuEntry(e, e.name)).toList();
return DropdownMenu(
return DropdownMenu<Difficulty?>(
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<Difficulty> _toDropdownMenuEntry(
Difficulty difficulty, String text) =>
DropdownMenuEntry(value: difficulty, label: text);
}

View File

@@ -12,17 +12,14 @@ class IngredientsBottomsheet extends StatefulWidget {
}
class _IngredientsBottomsheetState extends State<IngredientsBottomsheet> {
TextEditingController dropdownController = TextEditingController();
final List<DropdownMenuEntry<Unit>> unitEntries = [];
final List<DropdownMenuEntry<Ingredient>> ingredientEntries = [];
final List<DropdownMenuEntry<Unit>> 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<IngredientsBottomsheet> {
void onClosing() {}
Widget _bottomSheetContent(BuildContext context) {
return Padding(
return Wrap(
children: [
Padding(
padding: EdgeInsets.only(
top: 20,
left: 10,
right: 10,
left: 20,
right: 20,
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Row(
children: [
Expanded(
flex: 4,
child: DropdownMenu<Ingredient>(
DropdownMenu<Ingredient?>(
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: InputDecoration(
decoration: const InputDecoration(
label: Text('Amount'),
),
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface),
),
),
DropdownMenu<Unit>(
DropdownMenu<Unit?>(
label: const Text('Unit'),
width: 150,
requestFocusOnTap: true,
controller: dropdownController,
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),
),
],
),
],
),
),
const SizedBox(
height: 200,
width: 400,
),
Padding(
padding: const EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: _cancelTapped,
child: const Text('Cancel'),
),
TextButton(
onPressed: _finishTapped,
child: const Text('Finish'),
),
TextButton(
onPressed: _nextTapped,
child: const Text('Next'),
),
],
),
),
],
);
}
@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() {}
}