calorimeter/lib/perday_widget.dart

44 lines
1.3 KiB
Dart
Raw Normal View History

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) {
2024-06-01 10:41:58 +00:00
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) {
2024-06-01 10:41:58 +00:00
if (index + 1 == entryList.length + 1) return EnterFoodWidget();
return entryList[index];
},
),
);
}
}