Marco
2509c1721c
1. Make EnterFoodWidget animated 2. Fix exception when reading quantity for a food. Introduce first integration test
99 lines
3.4 KiB
Dart
99 lines
3.4 KiB
Dart
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
/* Copyright (C) 2024 Marco Groß <mgross@sw-gross.de> */
|
|
|
|
import 'package:calorimeter/food_entry/enter_food_widget.dart';
|
|
import 'package:calorimeter/food_entry/food_entry_bloc.dart';
|
|
import 'package:calorimeter/food_entry/food_entry_widget.dart';
|
|
import 'package:calorimeter/storage/storage.dart';
|
|
import 'package:calorimeter/utils/row_with_spacers_widget.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
class FoodEntryList extends StatelessWidget {
|
|
final List<FoodEntryState> entries;
|
|
final DateTime date;
|
|
|
|
const FoodEntryList({
|
|
required this.entries,
|
|
required this.date,
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var headerStyle = TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: Theme.of(context).colorScheme.onSurface);
|
|
|
|
return Column(
|
|
children: [
|
|
if (entries.isNotEmpty)
|
|
RowWidget(
|
|
showDividers: true,
|
|
Text(AppLocalizations.of(context)!.name, style: headerStyle),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Text(AppLocalizations.of(context)!.amountPer,
|
|
style: headerStyle),
|
|
),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Text(AppLocalizations.of(context)!.kcalper,
|
|
style: headerStyle),
|
|
),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Text(AppLocalizations.of(context)!.kcalSum,
|
|
style: headerStyle),
|
|
),
|
|
),
|
|
if (entries.isNotEmpty) Divider(),
|
|
Expanded(
|
|
child: ListView.separated(
|
|
itemCount: entries.length + 1,
|
|
separatorBuilder: (context, index) {
|
|
return Divider();
|
|
},
|
|
itemBuilder: (BuildContext itemBuilderContext, int listIndex) {
|
|
//last item in list is the widget to enter food
|
|
if (listIndex == entries.length) {
|
|
return EnterFoodWidget(
|
|
foodEntryLookupDatabase:
|
|
FoodStorage.getInstance().getFoodEntryLookupDatabase,
|
|
onAdd: (context, entry) {
|
|
context
|
|
.read<FoodEntryBloc>()
|
|
.add(FoodEntryEvent(entry: entry, forDate: date));
|
|
},
|
|
);
|
|
}
|
|
|
|
var entryIndex = listIndex;
|
|
return FoodEntryWidget(
|
|
key: ValueKey(entries[entryIndex].id),
|
|
entry: entries[entryIndex],
|
|
onDelete: (_, id) {
|
|
context
|
|
.read<FoodEntryBloc>()
|
|
.add(FoodDeletionEvent(entryID: id, forDate: date));
|
|
},
|
|
onChange: (_, changedEntry) {
|
|
context.read<FoodEntryBloc>().add(
|
|
FoodChangedEvent(newEntry: changedEntry, forDate: date),
|
|
);
|
|
},
|
|
onTap: (_, tappedEntry) {
|
|
context.read<FoodEntryBloc>().add(
|
|
FoodEntryTapped(entry: tappedEntry, forDate: date),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|