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