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.
51 lines
1.4 KiB
Dart
51 lines
1.4 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 '../widgets/category_grid_item.dart';
|
|
|
|
class CategoriesScreen extends StatelessWidget {
|
|
const CategoriesScreen({super.key});
|
|
|
|
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,
|
|
),
|
|
),
|
|
); //Navigator.push(context, route);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Pick your category'),
|
|
),
|
|
body: 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);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|