2023-07-29 19:21:02 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-07-30 15:31:36 +02:00
|
|
|
import 'package:fooder/models/meal.dart';
|
|
|
|
import 'package:fooder/widgets/entry.dart';
|
|
|
|
import 'package:fooder/widgets/macro.dart';
|
|
|
|
import 'package:fooder/screens/edit_entry.dart';
|
|
|
|
import 'package:fooder/client.dart';
|
2023-07-29 19:21:02 +02:00
|
|
|
import 'dart:core';
|
|
|
|
|
|
|
|
|
|
|
|
class MealWidget extends StatelessWidget {
|
|
|
|
final Meal meal;
|
2023-07-30 13:09:41 +02:00
|
|
|
final ApiClient apiClient;
|
|
|
|
final Function() refreshParent;
|
2023-07-29 19:21:02 +02:00
|
|
|
|
2023-07-30 13:09:41 +02:00
|
|
|
const MealWidget({super.key, required this.meal, required this.apiClient, required this.refreshParent});
|
2023-07-29 19:21:02 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Card(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 36.0, left: 6.0, right: 6.0, bottom: 6.0),
|
|
|
|
child: ExpansionTile(
|
2023-07-29 23:54:51 +02:00
|
|
|
title: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
meal.name,
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
),
|
|
|
|
),
|
2023-07-30 13:09:41 +02:00
|
|
|
Text("${meal.calories.toStringAsFixed(1)} kcal"),
|
2023-07-29 23:54:51 +02:00
|
|
|
],
|
2023-07-29 19:21:02 +02:00
|
|
|
),
|
2023-07-30 13:09:41 +02:00
|
|
|
MacroWidget(
|
|
|
|
protein: meal.protein,
|
|
|
|
carb: meal.carb,
|
|
|
|
fat: meal.fat,
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
2023-07-29 23:54:51 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
children: <Widget>[
|
|
|
|
for (var entry in meal.entries)
|
2023-07-30 13:09:41 +02:00
|
|
|
ListTile(
|
|
|
|
title: EntryWidget(
|
|
|
|
entry: entry,
|
2023-07-29 23:54:51 +02:00
|
|
|
),
|
2023-07-30 13:09:41 +02:00
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => EditEntryScreen(
|
|
|
|
apiClient: apiClient,
|
|
|
|
entry: entry,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
).then((_) {
|
|
|
|
refreshParent();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
)
|
2023-07-29 19:21:02 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|