calorimeter/lib/perdate/entry_list.dart
Marco a7a7f44050 Make scanned widgets appear in the list instead of putting the info into
the EnterFoodWidget.

1. Make scanned foods appear in the list of foods
2. Remove Controller for entering food

This commit removes the EnterFoodController that was used to put a
scanned food into the EnterFoodWidget.
This is now unnecessary because scanning a product will be distributed
via the FoodBLoC.
2024-09-24 14:41:42 +02:00

55 lines
1.6 KiB
Dart

import 'package:calorimeter/food_entry/enter_food_widget.dart';
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
import 'package:calorimeter/food_entry/food_entry_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class FoodEntryList extends StatelessWidget {
final List<FoodEntryState> entries;
const FoodEntryList({
required this.entries,
super.key,
});
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: entries.length + 1,
itemBuilder: (BuildContext itemBuilderContext, int listIndex) {
//last item in list is the widget to enter food
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],
onDelete: (callbackContext, id) {
callbackContext.read<FoodEntryBloc>().add(FoodDeletionEvent(
entryID: id,
));
},
),
const Divider(),
],
);
},
);
}
}