54 lines
1.5 KiB
Dart
54 lines
1.5 KiB
Dart
|
import 'package:calodiary/enter_food_widget.dart';
|
||
|
import 'package:calodiary/food_entry/food_entry_bloc.dart';
|
||
|
import 'package:calodiary/food_entry/food_entry_widget.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||
|
|
||
|
class FoodEntryList extends StatelessWidget {
|
||
|
final List<FoodEntry> 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) {
|
||
|
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(),
|
||
|
],
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|