diff --git a/lib/screens/meal_details.dart b/lib/screens/meal_details.dart new file mode 100644 index 0000000..56608e0 --- /dev/null +++ b/lib/screens/meal_details.dart @@ -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, + ), + ), + ) + ], + ), + ), + ); + } +} diff --git a/lib/screens/meals.dart b/lib/screens/meals.dart index f9a147b..dc2f3e7 100644 --- a/lib/screens/meals.dart +++ b/lib/screens/meals.dart @@ -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 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( diff --git a/lib/widgets/meal_item.dart b/lib/widgets/meal_item.dart index 275ee62..141554e 100644 --- a/lib/widgets/meal_item.dart +++ b/lib/widgets/meal_item.dart @@ -1,14 +1,27 @@ import 'package:flutter/material.dart'; import 'package:flutter_navigation/models/meal.dart'; +import 'package:flutter_navigation/widgets/meal_item_trait.dart'; import 'package:transparent_image/transparent_image.dart'; class MealItem extends StatelessWidget { const MealItem({ super.key, required this.meal, + required this.onSelectMeal, }); 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 Widget build(BuildContext context) { @@ -20,7 +33,9 @@ class MealItem extends StatelessWidget { clipBehavior: Clip.hardEdge, elevation: 2, child: InkWell( - onTap: () {}, + onTap: () { + onSelectMeal(meal); + }, child: Stack( children: [ FadeInImage( @@ -56,7 +71,17 @@ class MealItem extends StatelessWidget { ), const SizedBox(height: 12), 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), + ], ), ], ), diff --git a/lib/widgets/meal_item_trait.dart b/lib/widgets/meal_item_trait.dart new file mode 100644 index 0000000..3fc9ff0 --- /dev/null +++ b/lib/widgets/meal_item_trait.dart @@ -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, + ), + ), + ]); + } +}