2024-09-06 16:51:24 +00:00
|
|
|
import 'package:calorimeter/food_entry/enter_food_widget.dart';
|
2024-09-06 17:00:25 +00:00
|
|
|
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
|
|
|
import 'package:calorimeter/food_entry/food_entry_widget.dart';
|
2024-09-06 11:48:56 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
|
|
|
class FoodEntryList extends StatelessWidget {
|
2024-09-09 20:41:48 +00:00
|
|
|
final List<FoodEntryState> entries;
|
2024-09-06 11:48:56 +00:00
|
|
|
|
|
|
|
const FoodEntryList({
|
|
|
|
required this.entries,
|
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ListView.builder(
|
|
|
|
itemCount: entries.length + 1,
|
|
|
|
itemBuilder: (BuildContext itemBuilderContext, int listIndex) {
|
2024-09-09 20:41:48 +00:00
|
|
|
//last item in list is the widget to enter food
|
2024-09-06 11:48:56 +00:00
|
|
|
if (listIndex == entries.length) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
EnterFoodWidget(
|
|
|
|
onAdd: (context, entry) {
|
|
|
|
context
|
|
|
|
.read<FoodEntryBloc>()
|
|
|
|
.add(FoodEntryEvent(entry: entry));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(height: 75),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var entryIndex = listIndex;
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
FoodEntryWidget(
|
|
|
|
key: ValueKey(entries[entryIndex].id),
|
|
|
|
entry: entries[entryIndex],
|
2024-09-24 15:23:01 +00:00
|
|
|
onDelete: (_, id) {
|
|
|
|
context.read<FoodEntryBloc>().add(FoodDeletionEvent(
|
2024-09-06 11:48:56 +00:00
|
|
|
entryID: id,
|
|
|
|
));
|
|
|
|
},
|
2024-09-24 15:23:01 +00:00
|
|
|
onChange: (_, changedEntry) {
|
|
|
|
context
|
|
|
|
.read<FoodEntryBloc>()
|
|
|
|
.add(FoodChangedEvent(newEntry: changedEntry));
|
|
|
|
},
|
2024-09-25 15:33:40 +00:00
|
|
|
onTap: (_, tappedEntry) {
|
|
|
|
context
|
|
|
|
.read<FoodEntryBloc>()
|
|
|
|
.add(FoodEntryTapped(entryID: tappedEntry.id));
|
|
|
|
},
|
2024-09-06 11:48:56 +00:00
|
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|