73 lines
2.6 KiB
Dart
73 lines
2.6 KiB
Dart
import 'package:calodiary/app_drawer.dart';
|
|
import 'package:calodiary/utils/calendar_floating_button.dart';
|
|
import 'package:calodiary/perdate/entry_list.dart';
|
|
import 'package:calodiary/food_entry/food_entry_bloc.dart';
|
|
import 'package:calodiary/storage/storage.dart';
|
|
import 'package:calodiary/utils/sum_widget.dart';
|
|
import 'package:calodiary/utils/theme_switcher_button.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class PerDateWidget extends StatefulWidget {
|
|
final DateTime date;
|
|
const PerDateWidget({super.key, required this.date});
|
|
|
|
@override
|
|
State<PerDateWidget> createState() => _PerDateWidgetState();
|
|
}
|
|
|
|
class _PerDateWidgetState extends State<PerDateWidget> {
|
|
late FoodStorage storage;
|
|
late Future<List<FoodEntry>> entriesFuture;
|
|
List<FoodEntry> entries = [];
|
|
String formattedDate = '';
|
|
|
|
@override
|
|
void initState() {
|
|
formattedDate = DateFormat.yMMMMd('de').format(widget.date);
|
|
storage = FoodStorage.getInstance();
|
|
entriesFuture = storage.getEntriesForDate(widget.date);
|
|
entriesFuture.then((val) {
|
|
entries = val;
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FutureBuilder(
|
|
future: entriesFuture,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState != ConnectionState.done) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
} else {
|
|
return BlocProvider(
|
|
create: (context) => FoodEntryBloc(
|
|
initialState: FoodEntryState(foodEntries: entries),
|
|
storage: storage,
|
|
forDate: widget.date),
|
|
child: BlocBuilder<FoodEntryBloc, FoodEntryState>(
|
|
builder: (context, state) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(formattedDate),
|
|
actions: const [ThemeSwitcherButton()],
|
|
),
|
|
body: FoodEntryList(entries: state.foodEntries),
|
|
bottomNavigationBar: BottomAppBar(
|
|
shape: const CircularNotchedRectangle(),
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
child: SumWidget(foodEntries: state.foodEntries)),
|
|
drawer: const AppDrawer(),
|
|
floatingActionButton:
|
|
CalendarFloatingButton(date: widget.date),
|
|
floatingActionButtonLocation:
|
|
FloatingActionButtonLocation.endDocked);
|
|
}),
|
|
);
|
|
}
|
|
});
|
|
}
|
|
}
|