2024-06-09 17:06:10 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2024-06-10 01:06:56 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2024-06-09 17:06:10 +00:00
|
|
|
import 'package:kalodings/app_drawer.dart';
|
2024-06-10 01:06:56 +00:00
|
|
|
import 'package:kalodings/calendar_floating_button.dart';
|
2024-06-09 17:06:10 +00:00
|
|
|
import 'package:kalodings/enter_food_widget.dart';
|
|
|
|
import 'package:kalodings/food_entry_bloc.dart';
|
|
|
|
import 'package:kalodings/food_entry_widget.dart';
|
|
|
|
import 'package:kalodings/sum_widget.dart';
|
|
|
|
|
2024-06-09 21:25:18 +00:00
|
|
|
class PerDateWidget extends StatelessWidget {
|
2024-06-09 17:06:10 +00:00
|
|
|
final DateTime date;
|
|
|
|
const PerDateWidget(this.date, {super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-06-10 01:06:56 +00:00
|
|
|
var formattedDate = DateFormat.yMMMMd('de').format(date);
|
2024-06-09 17:06:10 +00:00
|
|
|
return Scaffold(
|
2024-06-10 01:06:56 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(formattedDate),
|
|
|
|
),
|
|
|
|
drawer: const AppDrawer(),
|
|
|
|
body: BlocBuilder<FoodEntryBloc, FoodEntryState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
return ListView.builder(
|
|
|
|
itemCount: state.foodEntries.length + 2,
|
|
|
|
itemBuilder: (BuildContext itemBuilderContext, int index) {
|
|
|
|
if (index == state.foodEntries.length) {
|
2024-06-10 01:31:06 +00:00
|
|
|
return Padding(
|
2024-06-10 15:35:21 +00:00
|
|
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
2024-06-10 01:31:06 +00:00
|
|
|
child: SumWidget(limit: state.kcalLimit),
|
|
|
|
);
|
2024-06-10 01:06:56 +00:00
|
|
|
}
|
|
|
|
if (index == state.foodEntries.length + 1) {
|
2024-06-10 01:31:06 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
EnterFoodWidget(
|
|
|
|
onAdd: (context, entry) {
|
|
|
|
context
|
|
|
|
.read<FoodEntryBloc>()
|
|
|
|
.add(FoodEntryEvent(entry: entry, date: date));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(height: 75),
|
|
|
|
],
|
2024-06-10 01:06:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FoodEntryWidget(
|
|
|
|
entry: state.foodEntries[index],
|
|
|
|
onDelete: (callbackContext) {
|
|
|
|
callbackContext.read<FoodEntryBloc>().add(
|
|
|
|
FoodDeletionEvent(
|
|
|
|
entryID: state.foodEntries[index].id, date: date),
|
|
|
|
);
|
2024-06-09 17:06:10 +00:00
|
|
|
},
|
|
|
|
);
|
2024-06-10 01:06:56 +00:00
|
|
|
},
|
2024-06-09 21:25:18 +00:00
|
|
|
);
|
2024-06-09 17:06:10 +00:00
|
|
|
},
|
2024-06-10 01:06:56 +00:00
|
|
|
),
|
|
|
|
floatingActionButton: CalendarFloatingButton(date: date));
|
2024-06-09 17:06:10 +00:00
|
|
|
}
|
|
|
|
}
|