77 lines
2.4 KiB
Dart
77 lines
2.4 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||
|
import 'package:go_router/go_router.dart';
|
||
|
import 'package:kalodings/app_drawer.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 StatefulWidget {
|
||
|
final DateTime date;
|
||
|
const PerDateWidget(this.date, {super.key});
|
||
|
|
||
|
@override
|
||
|
State<PerDateWidget> createState() => _PerDateWidgetState();
|
||
|
}
|
||
|
|
||
|
class _PerDateWidgetState extends State<PerDateWidget> {
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
|
||
|
context
|
||
|
.read<FoodEntryBloc>()
|
||
|
.add(PageChangedEvent(changedToDate: widget.date));
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
title: Text(widget.date.toString()),
|
||
|
),
|
||
|
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 const SumWidget();
|
||
|
}
|
||
|
if (index == state.foodEntries.length + 1) {
|
||
|
return EnterFoodWidget(
|
||
|
onAdd: (context, entry) {
|
||
|
context
|
||
|
.read<FoodEntryBloc>()
|
||
|
.add(FoodEntryEvent(entry: entry, date: widget.date));
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return FoodEntryWidget(
|
||
|
entry: state.foodEntries[index],
|
||
|
onDelete: (callbackContext) {
|
||
|
callbackContext.read<FoodEntryBloc>().add(
|
||
|
FoodDeletionEvent(
|
||
|
entryID: state.foodEntries[index].id,
|
||
|
date: widget.date),
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
},
|
||
|
),
|
||
|
floatingActionButton: FloatingActionButton(
|
||
|
onPressed: () {
|
||
|
context.goNamed('calendar');
|
||
|
},
|
||
|
child: const Icon(Icons.today)),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
void deleteCallback(BuildContext context, String idToDelete, DateTime date) {}
|
||
|
}
|