calorimeter/lib/food_entry_widget.dart
Marco b83f547f6b Implement food entry lookup on entering a food name.
Now, an on-the-fly food lookup is created from existing entries on startup. Those entries are used to make suggestions when the user is typing to enter new food entries.
2024-09-04 22:47:37 +02:00

40 lines
1.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:calodiary/food_entry_bloc.dart';
import 'package:calodiary/row_with_spacers_widget.dart';
class FoodEntryWidget extends StatelessWidget {
final FoodEntry entry;
final Function(BuildContext context, String id) onDelete;
const FoodEntryWidget(
{super.key, required this.entry, required this.onDelete});
@override
Widget build(BuildContext context) {
return Dismissible(
key: ValueKey(entry.id),
onDismissed: (direction) {
onDelete(context, entry.id);
},
child: Card(
elevation: 5.0,
child: Padding(
padding: const EdgeInsets.only(left: 4.0),
child: RowWidget(
Text(entry.name),
Text(entry.mass.ceil().toString()),
Text(entry.kcalPerMass.ceil().toString()),
Text((entry.mass * entry.kcalPerMass / 100).ceil().toString()),
IconButton(
style: IconButton.styleFrom(padding: EdgeInsets.zero),
onPressed: () {
onDelete(context, entry.id);
},
icon: const Icon(Icons.delete_forever_rounded)),
),
),
),
);
}
}