165 Start

This commit is contained in:
2024-03-05 16:05:47 +01:00
parent ccefd0e0fa
commit 9f74693b2f
4 changed files with 147 additions and 3 deletions
+76
View File
@@ -0,0 +1,76 @@
import 'package:flutter/material.dart';
import '../models/meal.dart';
class MealDetailsScreen extends StatelessWidget {
const MealDetailsScreen({
super.key,
required this.meal,
});
final Meal meal;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(meal.title),
),
body: SingleChildScrollView(
child: Column(
children: [
Image.network(
meal.imageUrl,
width: double.infinity,
height: 300,
fit: BoxFit.cover,
),
const SizedBox(height: 14),
Text(
'Ingredients',
style: Theme.of(context).textTheme.titleLarge!.copyWith(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 14,
),
for (final ingredient in meal.ingredients)
Text(
ingredient,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.onBackground,
),
),
const SizedBox(height: 24),
Text(
'Steps',
style: Theme.of(context).textTheme.titleLarge!.copyWith(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 14,
),
for (final step in meal.steps)
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
child: Text(
step,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: Theme.of(context).colorScheme.onBackground,
),
),
)
],
),
),
);
}
}
+14 -1
View File
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_navigation/screens/meal_details.dart';
import 'package:flutter_navigation/widgets/meal_item.dart';
import '../models/meal.dart';
@@ -9,6 +10,14 @@ class MealsScreen extends StatelessWidget {
final String title;
final List<Meal> meals;
void selectMeal(BuildContext context, Meal meal) {
Navigator.of(context).push(MaterialPageRoute(
builder: (ctx) => MealDetailsScreen(
meal: meal,
),
));
}
@override
Widget build(BuildContext context) {
Widget content = Center(
@@ -35,7 +44,11 @@ class MealsScreen extends StatelessWidget {
if (meals.isNotEmpty) {
content = ListView.builder(
itemCount: meals.length,
itemBuilder: (ctx, index) => MealItem(meal: meals[index]),
itemBuilder: (ctx, index) => MealItem(
meal: meals[index],
onSelectMeal: (meal) {
selectMeal(context, meal);
}),
);
}
return Scaffold(