added expandable list of ingredients

This commit is contained in:
SomnusVeritas
2023-10-03 17:02:07 +02:00
parent 2d77247f1f
commit 10463bb61a
6 changed files with 128 additions and 48 deletions

View File

@@ -1,41 +0,0 @@
import 'package:flutter/material.dart';
class DropdownTextfield extends StatefulWidget {
const DropdownTextfield({super.key});
@override
State<DropdownTextfield> createState() => _DropdownTextfieldState();
}
class _DropdownTextfieldState extends State<DropdownTextfield> {
List<DropdownMenuItem> 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) {}
}

View File

@@ -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<IngredientsWidget> createState() => _IngredientsWidgetState();
}
class _IngredientsWidgetState extends State<IngredientsWidget> {
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<String>(
decoration: const InputDecoration(
label: Text('Unit'),
),
isDense: true,
items: constants.units
.map(
(e) => DropdownMenuItem<String>(
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) {}
}