2024-05-29 22:58:26 +00:00
|
|
|
import 'package:flutter/material.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/utils/row_with_spacers_widget.dart';
|
2024-05-29 22:58:26 +00:00
|
|
|
|
2024-09-06 00:23:47 +00:00
|
|
|
class FoodEntryWidget extends StatefulWidget {
|
2024-06-09 12:42:17 +00:00
|
|
|
final FoodEntry entry;
|
2024-09-04 20:47:32 +00:00
|
|
|
final Function(BuildContext context, String id) onDelete;
|
2024-06-01 10:41:58 +00:00
|
|
|
|
2024-06-09 17:06:10 +00:00
|
|
|
const FoodEntryWidget(
|
|
|
|
{super.key, required this.entry, required this.onDelete});
|
2024-05-29 22:58:26 +00:00
|
|
|
|
2024-09-06 00:23:47 +00:00
|
|
|
@override
|
|
|
|
State<FoodEntryWidget> createState() => _FoodEntryWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FoodEntryWidgetState extends State<FoodEntryWidget> {
|
|
|
|
late bool showCancelAndDelete;
|
2024-09-06 22:02:01 +00:00
|
|
|
|
2024-09-06 00:23:47 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
showCancelAndDelete = false;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2024-05-29 22:58:26 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-09-06 00:23:47 +00:00
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
showCancelAndDelete = !showCancelAndDelete;
|
|
|
|
});
|
2024-09-04 20:47:32 +00:00
|
|
|
},
|
2024-09-06 00:23:47 +00:00
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
Positioned.fill(
|
|
|
|
child: Stack(children: [
|
|
|
|
Positioned.fill(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
|
|
|
child: RowWidget(
|
|
|
|
Text(widget.entry.name),
|
|
|
|
Text(widget.entry.mass.ceil().toString(),
|
|
|
|
textAlign: TextAlign.end),
|
|
|
|
Text(widget.entry.kcalPerMass.ceil().toString(),
|
|
|
|
textAlign: TextAlign.end),
|
|
|
|
Opacity(
|
|
|
|
opacity: showCancelAndDelete ? 0.0 : 1.0,
|
|
|
|
child: Text(
|
|
|
|
(widget.entry.mass * widget.entry.kcalPerMass / 100)
|
|
|
|
.ceil()
|
|
|
|
.toString(),
|
|
|
|
textAlign: TextAlign.end),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Opacity(
|
|
|
|
opacity: showCancelAndDelete ? 0.66 : 0.0,
|
|
|
|
child: Container(
|
|
|
|
color: Theme.of(context).colorScheme.secondary)),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
Opacity(
|
|
|
|
opacity: showCancelAndDelete ? 1.0 : 0.0,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
child: IconButton(
|
2024-09-06 11:48:56 +00:00
|
|
|
padding: const EdgeInsets.all(0.0),
|
2024-09-06 00:23:47 +00:00
|
|
|
icon: const Icon(Icons.cancel),
|
|
|
|
onPressed: showCancelAndDelete
|
|
|
|
? () => setState(() {
|
|
|
|
showCancelAndDelete = false;
|
|
|
|
})
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
child: IconButton(
|
2024-09-06 11:48:56 +00:00
|
|
|
padding: const EdgeInsets.all(0.0),
|
2024-09-06 00:23:47 +00:00
|
|
|
iconSize: 24,
|
|
|
|
icon: const Icon(Icons.delete),
|
|
|
|
color: Colors.redAccent,
|
|
|
|
onPressed: showCancelAndDelete
|
|
|
|
? () => widget.onDelete(context, widget.entry.id)
|
|
|
|
: null),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-09-04 20:47:32 +00:00
|
|
|
),
|
2024-09-06 00:23:47 +00:00
|
|
|
],
|
2024-06-09 12:42:17 +00:00
|
|
|
),
|
2024-05-29 22:58:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|