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.
50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:meals/data/dummy_categories.dart';
|
|
import 'package:meals/models/Category.dart';
|
|
import 'package:meals/models/Meal.dart';
|
|
import 'package:meals/screens/MealsScreen.dart';
|
|
import 'package:meals/widgets/CategoryGridItem.dart';
|
|
|
|
class CategoriesScreen extends StatelessWidget {
|
|
final void Function(Meal meal) onToggleFavorite;
|
|
|
|
const CategoriesScreen({super.key, required this.onToggleFavorite});
|
|
|
|
void _selectCategory(BuildContext context, Category category) {
|
|
final meals = dummyMeals
|
|
.where((Meal meal) => meal.categories.contains(category.id))
|
|
.toList();
|
|
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (ctx) =>
|
|
MealsScreen(title: category.title,
|
|
meals: meals,
|
|
onToggleFavorite: onToggleFavorite,)));
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GridView(
|
|
padding: const EdgeInsets.all(24),
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
childAspectRatio: 1.5,
|
|
crossAxisSpacing: 20,
|
|
mainAxisSpacing: 20,
|
|
),
|
|
children: [
|
|
for (final category in availableCategories)
|
|
CategoryGridItem(
|
|
category: category,
|
|
onClickCallback: () {
|
|
_selectCategory(
|
|
context,
|
|
category,
|
|
);
|
|
})
|
|
]);
|
|
}
|
|
}
|