2024-09-06 16:51:24 +00:00
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
import 'package:calorimeter/food_scan/food_fact_lookup.dart';
|
|
|
|
import 'package:calorimeter/utils/app_drawer.dart';
|
2024-09-06 17:00:25 +00:00
|
|
|
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
2024-09-06 16:51:24 +00:00
|
|
|
import 'package:calorimeter/perdate/entry_list.dart';
|
2024-09-06 17:00:25 +00:00
|
|
|
import 'package:calorimeter/storage/storage.dart';
|
2024-09-06 16:51:24 +00:00
|
|
|
import 'package:calorimeter/utils/calendar_floating_button.dart';
|
|
|
|
import 'package:calorimeter/utils/rectangular_notch_shape.dart';
|
2024-09-06 17:00:25 +00:00
|
|
|
import 'package:calorimeter/utils/sum_widget.dart';
|
|
|
|
import 'package:calorimeter/utils/theme_switcher_button.dart';
|
2024-09-06 11:48:56 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-09-06 16:51:24 +00:00
|
|
|
import 'package:flutter_barcode_scanner/flutter_barcode_scanner.dart';
|
2024-09-06 11:48:56 +00:00
|
|
|
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 = '';
|
2024-09-06 16:51:24 +00:00
|
|
|
FoodFactLookupClient client = FoodFactLookupClient();
|
2024-09-06 11:48:56 +00:00
|
|
|
|
|
|
|
@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(
|
2024-09-06 16:51:24 +00:00
|
|
|
shape: const RectangularNotchShape(),
|
2024-09-06 11:48:56 +00:00
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
child: SumWidget(foodEntries: state.foodEntries)),
|
|
|
|
drawer: const AppDrawer(),
|
2024-09-06 16:51:24 +00:00
|
|
|
floatingActionButton: OverflowBar(children: [
|
|
|
|
FloatingActionButton(
|
|
|
|
child: const Icon(Icons.barcode_reader),
|
|
|
|
onPressed: () async {
|
|
|
|
String ean = await FlutterBarcodeScanner.scanBarcode(
|
|
|
|
"#ffffff", "hallo", true, ScanMode.BARCODE);
|
|
|
|
client.retrieveFoodInfo(ean).then((val) {
|
|
|
|
log(val.name);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
CalendarFloatingButton(date: widget.date),
|
|
|
|
]),
|
2024-09-06 11:48:56 +00:00
|
|
|
floatingActionButtonLocation:
|
|
|
|
FloatingActionButtonLocation.endDocked);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|