168 Start
This commit is contained in:
+28
-19
@@ -3,19 +3,28 @@ 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});
|
||||
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();
|
||||
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);
|
||||
@@ -24,22 +33,22 @@ class CategoriesScreen extends StatelessWidget {
|
||||
@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);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
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);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user