improve ui
This commit is contained in:
parent
7712373388
commit
a5afda8de6
@ -13,38 +13,113 @@ class EnterFoodWidget extends StatefulWidget {
|
||||
|
||||
class _EnterFoodWidgetState extends State<EnterFoodWidget> {
|
||||
String perFoodresult = "dings";
|
||||
TextEditingController nameController = TextEditingController();
|
||||
TextEditingController massController = TextEditingController();
|
||||
TextEditingController kcalPerMassController = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var nameWidget = TextField(
|
||||
decoration: const InputDecoration(hintText: "Name"),
|
||||
controller: nameController,
|
||||
);
|
||||
|
||||
var massWidget = TextField(
|
||||
decoration: const InputDecoration(hintText: "Menge"),
|
||||
keyboardType: TextInputType.number,
|
||||
controller: massController,
|
||||
);
|
||||
|
||||
var kcalPerMassWidget = TextField(
|
||||
decoration: const InputDecoration(hintText: "kcal pro 100g"),
|
||||
controller: kcalPerMassController);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
const Spacer(flex: 1),
|
||||
const Expanded(
|
||||
flex: 4,
|
||||
child:
|
||||
TextField(decoration: InputDecoration(hintText: "Name"))),
|
||||
const Expanded(
|
||||
flex: 4,
|
||||
child:
|
||||
TextField(decoration: InputDecoration(hintText: "Menge"))),
|
||||
const Expanded(
|
||||
flex: 4,
|
||||
child: TextField(
|
||||
decoration: InputDecoration(hintText: "kcal pro 100g")),
|
||||
RowWidgetWithSpacers(
|
||||
nameWidget,
|
||||
massWidget,
|
||||
kcalPerMassWidget,
|
||||
),
|
||||
Text(perFoodresult),
|
||||
const Spacer(flex: 1),
|
||||
],
|
||||
),
|
||||
ElevatedButton(
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ElevatedButton(
|
||||
child: const Text("Hinzufügen"),
|
||||
onPressed: () {
|
||||
var entry =
|
||||
FoodEntry(name: '', mass: 2.0, kcal: 100, kcalPerMass: 200);
|
||||
double massAsNumber = 0.0;
|
||||
double kcalPerMassAsNumber = 0.0;
|
||||
|
||||
try {
|
||||
massAsNumber =
|
||||
double.parse(massController.text.replaceAll(",", "."));
|
||||
} catch (e) {
|
||||
var snackbar = const SnackBar(
|
||||
content: Text("Menge muss eine Zahl sein"));
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackbar);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
kcalPerMassAsNumber = double.parse(
|
||||
kcalPerMassController.text.replaceAll(",", "."));
|
||||
} catch (e) {
|
||||
var snackbar = const SnackBar(
|
||||
content: Text("'kcal pro 100g' muss eine Zahl sein"));
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackbar);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
massAsNumber =
|
||||
double.parse(massController.text.replaceAll(",", "."));
|
||||
} catch (e) {
|
||||
var snackbar = const SnackBar(
|
||||
content: Text("Menge muss eine Zahl sein"));
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackbar);
|
||||
return;
|
||||
}
|
||||
|
||||
var entry = FoodEntry(
|
||||
name: nameController.text,
|
||||
mass: massAsNumber,
|
||||
kcal: kcalPerMassAsNumber,
|
||||
kcalPerMass: 200);
|
||||
context.read<FoodEntryBloc>().add(FoodEntryEvent(entry: entry));
|
||||
}),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RowWidgetWithSpacers extends StatefulWidget {
|
||||
final Widget widget1;
|
||||
final Widget widget2;
|
||||
final Widget widget3;
|
||||
|
||||
const RowWidgetWithSpacers(this.widget1, this.widget2, this.widget3,
|
||||
{super.key});
|
||||
|
||||
@override
|
||||
State<RowWidgetWithSpacers> createState() => _RowWidgetWithSpacersState();
|
||||
}
|
||||
|
||||
class _RowWidgetWithSpacersState extends State<RowWidgetWithSpacers> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
const Spacer(flex: 1),
|
||||
Expanded(flex: 4, child: widget.widget1),
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: widget.widget2,
|
||||
),
|
||||
Expanded(flex: 4, child: widget.widget3),
|
||||
const Spacer(flex: 1),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -1,16 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kalodings/enter_food_widget.dart';
|
||||
|
||||
class FoodEntryWidget extends StatelessWidget {
|
||||
const FoodEntryWidget({super.key});
|
||||
final String name;
|
||||
final double mass;
|
||||
final double kcalPerMass;
|
||||
|
||||
const FoodEntryWidget(
|
||||
{super.key,
|
||||
required this.name,
|
||||
required this.mass,
|
||||
required this.kcalPerMass});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Row(
|
||||
children: [
|
||||
Text("Hier könnte ihre Werbung stehen"),
|
||||
Text("Hier könnte ihre Werbung stehen"),
|
||||
Text("Hier könnte ihre Werbung stehen"),
|
||||
],
|
||||
return RowWidgetWithSpacers(
|
||||
Text(name),
|
||||
Text(mass.toString()),
|
||||
Text(kcalPerMass.toString()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,10 @@ class _PerDayState extends State<PerDay> {
|
||||
var newEntryWidgets = <FoodEntryWidget>[];
|
||||
|
||||
for (var entry in state.foodEntries) {
|
||||
newEntryWidgets.add(FoodEntryWidget());
|
||||
newEntryWidgets.add(FoodEntryWidget(
|
||||
name: entry.name,
|
||||
mass: entry.mass,
|
||||
kcalPerMass: entry.kcalPerMass));
|
||||
}
|
||||
setState(() {
|
||||
entryList = newEntryWidgets;
|
||||
@ -31,11 +34,8 @@ class _PerDayState extends State<PerDay> {
|
||||
child: ListView.builder(
|
||||
itemCount: entryList.length + 1,
|
||||
itemBuilder: (BuildContext itemBuilderContext, int index) {
|
||||
if (index + 1 == entryList.length + 1)
|
||||
return EnterFoodWidget(
|
||||
perFoodresult: '',
|
||||
);
|
||||
return Text(index.toString());
|
||||
if (index + 1 == entryList.length + 1) return EnterFoodWidget();
|
||||
return entryList[index];
|
||||
},
|
||||
),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user