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.

74 lines
1.8 KiB
Dart

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';
class MealsScreen extends StatelessWidget {
const MealsScreen({
super.key,
this.title,
required this.meals,
required this.onToggleFavorites,
});
final String? title;
final List<Meal> meals;
final void Function(Meal meal) onToggleFavorites;
void selectMeal(BuildContext context, Meal meal) {
Navigator.of(context).push(MaterialPageRoute(
builder: (ctx) => MealDetailsScreen(
meal: meal,
onToggleFavorites: onToggleFavorites,
),
));
}
@override
Widget build(BuildContext context) {
Widget content = Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Uh oh ... nothing here!',
style: Theme.of(context).textTheme.headlineLarge!.copyWith(
color: Theme.of(context).colorScheme.onBackground,
),
),
const SizedBox(height: 16),
Text(
'Try selecting a different category!',
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
color: Theme.of(context).colorScheme.onBackground,
),
),
],
),
);
if (meals.isNotEmpty) {
content = ListView.builder(
itemCount: meals.length,
itemBuilder: (ctx, index) => MealItem(
meal: meals[index],
onSelectMeal: (meal) {
selectMeal(context, meal);
}),
);
}
if (title == null) {
return content;
}
return Scaffold(
appBar: AppBar(
title: Text(title!),
),
body: content,
);
}
}