calorimeter/lib/perday_widget.dart

44 lines
1.2 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) {
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());
},
),
);
}
}