162 Start
This commit is contained in:
@@ -1,11 +1,26 @@
|
||||
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(
|
||||
@@ -22,7 +37,12 @@ class CategoriesScreen extends StatelessWidget {
|
||||
),
|
||||
children: [
|
||||
for (final category in availableCategories)
|
||||
CategoryGridItem(category: category)
|
||||
CategoryGridItem(
|
||||
category: category,
|
||||
onSelectCategory: () {
|
||||
_selectCategory(context, category);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_navigation/widgets/meal_item.dart';
|
||||
|
||||
import '../models/meal.dart';
|
||||
|
||||
class MealsScreen extends StatelessWidget {
|
||||
const MealsScreen({super.key, required this.title, required this.meals});
|
||||
|
||||
final String title;
|
||||
final List<Meal> meals;
|
||||
|
||||
@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]),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(title),
|
||||
),
|
||||
body: content,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user