165 Start
This commit is contained in:
@@ -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
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_navigation/screens/meal_details.dart';
|
||||||
import 'package:flutter_navigation/widgets/meal_item.dart';
|
import 'package:flutter_navigation/widgets/meal_item.dart';
|
||||||
|
|
||||||
import '../models/meal.dart';
|
import '../models/meal.dart';
|
||||||
@@ -9,6 +10,14 @@ class MealsScreen extends StatelessWidget {
|
|||||||
final String title;
|
final String title;
|
||||||
final List<Meal> meals;
|
final List<Meal> meals;
|
||||||
|
|
||||||
|
void selectMeal(BuildContext context, Meal meal) {
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
builder: (ctx) => MealDetailsScreen(
|
||||||
|
meal: meal,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget content = Center(
|
Widget content = Center(
|
||||||
@@ -35,7 +44,11 @@ class MealsScreen extends StatelessWidget {
|
|||||||
if (meals.isNotEmpty) {
|
if (meals.isNotEmpty) {
|
||||||
content = ListView.builder(
|
content = ListView.builder(
|
||||||
itemCount: meals.length,
|
itemCount: meals.length,
|
||||||
itemBuilder: (ctx, index) => MealItem(meal: meals[index]),
|
itemBuilder: (ctx, index) => MealItem(
|
||||||
|
meal: meals[index],
|
||||||
|
onSelectMeal: (meal) {
|
||||||
|
selectMeal(context, meal);
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|||||||
@@ -1,14 +1,27 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_navigation/models/meal.dart';
|
import 'package:flutter_navigation/models/meal.dart';
|
||||||
|
import 'package:flutter_navigation/widgets/meal_item_trait.dart';
|
||||||
import 'package:transparent_image/transparent_image.dart';
|
import 'package:transparent_image/transparent_image.dart';
|
||||||
|
|
||||||
class MealItem extends StatelessWidget {
|
class MealItem extends StatelessWidget {
|
||||||
const MealItem({
|
const MealItem({
|
||||||
super.key,
|
super.key,
|
||||||
required this.meal,
|
required this.meal,
|
||||||
|
required this.onSelectMeal,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Meal meal;
|
final Meal meal;
|
||||||
|
final void Function(Meal meal) onSelectMeal;
|
||||||
|
|
||||||
|
String get complexityText {
|
||||||
|
return meal.complexity.name[0].toUpperCase() +
|
||||||
|
meal.complexity.name.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
String get affordabilityText {
|
||||||
|
return meal.affordability.name[0].toUpperCase() +
|
||||||
|
meal.affordability.name.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -20,7 +33,9 @@ class MealItem extends StatelessWidget {
|
|||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
elevation: 2,
|
elevation: 2,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
|
onSelectMeal(meal);
|
||||||
|
},
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
FadeInImage(
|
FadeInImage(
|
||||||
@@ -56,7 +71,17 @@ class MealItem extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Row(
|
Row(
|
||||||
children: [],
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
MealItemTrait(
|
||||||
|
icon: Icons.schedule,
|
||||||
|
label: '${meal.duration} min'),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
MealItemTrait(icon: Icons.work, label: complexityText),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
MealItemTrait(
|
||||||
|
icon: Icons.attach_money, label: affordabilityText),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class MealItemTrait extends StatelessWidget {
|
||||||
|
const MealItemTrait({
|
||||||
|
super.key,
|
||||||
|
required this.icon,
|
||||||
|
required this.label,
|
||||||
|
});
|
||||||
|
|
||||||
|
final IconData icon;
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(children: [
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
size: 17,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user