You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
meals/lib/screens/MealsScreen.dart

74 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:meals/models/Meal.dart';
import 'package:meals/screens/meal_details.dart';
import 'package:meals/widgets/MealItem.dart';
class MealsScreen extends StatelessWidget {
final String? title;
final List<Meal> meals;
final void Function(Meal meal) onToggleFavorite;
const MealsScreen(
{super.key,
this.title,
required this.meals,
required this.onToggleFavorite});
void _selectMeal(BuildContext buildContext, Meal meal) {
Navigator.push(
buildContext,
MaterialPageRoute(
builder: (ctx) => MealDetailScreen(
meal: meal,
onToggleFavorite: onToggleFavorite,
),
));
}
@override
Widget build(BuildContext context) {
final Widget content = meals.isEmpty
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'Oh, there is no meals right here.',
style: Theme.of(context).textTheme.headlineLarge!.copyWith(
color: Theme.of(context).colorScheme.onBackground,
),
),
const SizedBox(height: 16),
Text(
'Would you to try something else ?',
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Theme.of(context).colorScheme.onBackground,
),
),
],
),
)
: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return MealItem(
meal: meals[index],
callbackClickOnMeal: (meal) {
_selectMeal(context, meal);
},
);
},
itemCount: meals.length,
);
return title == null
? content
: Scaffold(
appBar: AppBar(
title: Text(title!),
),
body: content,
);
}
}