calorimeter/lib/perdate_widget.dart
2024-06-10 03:31:06 +02:00

65 lines
2.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import 'package:kalodings/app_drawer.dart';
import 'package:kalodings/calendar_floating_button.dart';
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';
class PerDateWidget extends StatelessWidget {
final DateTime date;
const PerDateWidget(this.date, {super.key});
@override
Widget build(BuildContext context) {
var formattedDate = DateFormat.yMMMMd('de').format(date);
return Scaffold(
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) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 15),
child: SumWidget(limit: state.kcalLimit),
);
}
if (index == state.foodEntries.length + 1) {
return Column(
children: [
EnterFoodWidget(
onAdd: (context, entry) {
context
.read<FoodEntryBloc>()
.add(FoodEntryEvent(entry: entry, date: date));
},
),
const SizedBox(height: 75),
],
);
}
return FoodEntryWidget(
entry: state.foodEntries[index],
onDelete: (callbackContext) {
callbackContext.read<FoodEntryBloc>().add(
FoodDeletionEvent(
entryID: state.foodEntries[index].id, date: date),
);
},
);
},
);
},
),
floatingActionButton: CalendarFloatingButton(date: date));
}
}