44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:kalodings/enter_food_widget.dart';
|
|
import 'package:kalodings/food_entry_bloc.dart';
|
|
import 'package:kalodings/food_entry_widget.dart';
|
|
|
|
class PerDay extends StatefulWidget {
|
|
const PerDay({super.key});
|
|
|
|
@override
|
|
State<PerDay> createState() => _PerDayState();
|
|
}
|
|
|
|
class _PerDayState extends State<PerDay> {
|
|
String perFoodresult = "Kalorien der Mahlzeit";
|
|
List<FoodEntryWidget> entryList = [];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocListener<FoodEntryBloc, FoodEntryState>(
|
|
listener: (listenerContext, state) {
|
|
var newEntryWidgets = <FoodEntryWidget>[];
|
|
|
|
for (var entry in state.foodEntries) {
|
|
newEntryWidgets.add(FoodEntryWidget(
|
|
name: entry.name,
|
|
mass: entry.mass,
|
|
kcalPerMass: entry.kcalPerMass));
|
|
}
|
|
setState(() {
|
|
entryList = newEntryWidgets;
|
|
});
|
|
},
|
|
child: ListView.builder(
|
|
itemCount: entryList.length + 1,
|
|
itemBuilder: (BuildContext itemBuilderContext, int index) {
|
|
if (index + 1 == entryList.length + 1) return EnterFoodWidget();
|
|
return entryList[index];
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|