calorimeter/lib/food_entry/food_entry_widget.dart

97 lines
3.1 KiB
Dart
Raw Normal View History

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';
class FoodEntryWidget extends StatefulWidget {
2024-06-09 12:42:17 +00:00
final FoodEntry entry;
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});
@override
State<FoodEntryWidget> createState() => _FoodEntryWidgetState();
}
class _FoodEntryWidgetState extends State<FoodEntryWidget> {
late bool showCancelAndDelete;
@override
void initState() {
showCancelAndDelete = false;
super.initState();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
setState(() {
showCancelAndDelete = !showCancelAndDelete;
});
},
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),
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),
iconSize: 24,
icon: const Icon(Icons.delete),
color: Colors.redAccent,
onPressed: showCancelAndDelete
? () => widget.onDelete(context, widget.entry.id)
: null),
),
],
),
),
],
2024-06-09 12:42:17 +00:00
),
);
}
}