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 createState() => _PerDayState(); } class _PerDayState extends State { String perFoodresult = "Kalorien der Mahlzeit"; List entryList = []; @override Widget build(BuildContext context) { return BlocListener( listener: (listenerContext, state) { var newEntryWidgets = []; for (var entry in state.foodEntries) { newEntryWidgets.add(FoodEntryWidget()); } setState(() { entryList = newEntryWidgets; }); }, 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()); }, ), ); } }