Skip to content

Commit

Permalink
tabs.dart is modified.
Browse files Browse the repository at this point in the history
  • Loading branch information
musamairshad committed Jun 28, 2023
1 parent 45ee073 commit d2a6b3c
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions lib/screens/tabs.dart
Original file line number Diff line number Diff line change
@@ -1,10 1,18 @@
import 'package:flutter/material.dart';
import 'package:meals_app/data/dummy_data.dart';
import 'package:meals_app/models/meal.dart';
import 'package:meals_app/widgets/main_drawer.dart';
import 'package:meals_app/screens/categories.dart';
import 'package:meals_app/screens/meals.dart';
import 'package:meals_app/screens/filters.dart';

const kInitialFilters = {
Filter.glutenFree: false,
Filter.lactoseFree: false,
Filter.vegetarian: false,
Filter.vegan: false,
};

class TabsScreen extends StatefulWidget {
const TabsScreen({super.key});
@override
Expand All @@ -16,6 24,7 @@ class TabsScreen extends StatefulWidget {
class _TabsScreenState extends State<TabsScreen> {
int _selectedPageIndex = 0;
final List<Meal> _favoriteMeals = [];
Map<Filter, bool> _selectedFilters = kInitialFilters;

void _showInfoMessage(String message) {
ScaffoldMessenger.of(context).clearSnackBars();
Expand Down Expand Up @@ -48,15 57,21 @@ class _TabsScreenState extends State<TabsScreen> {
});
}

void _setScreen(String identifier) {
void _setScreen(String identifier) async {
Navigator.of(context).pop();
if (identifier == 'filters') {
Navigator.of(context).push(
final result = await Navigator.of(context).push<Map<Filter, bool>>(
// before it was pushReplacement.
MaterialPageRoute(
builder: (ctx) => const FiltersScreen(),
builder: (ctx) => FiltersScreen(
currentFilters: _selectedFilters,
),
),
);
setState(() {
_selectedFilters = result ?? kInitialFilters;
});
// print(result);
}
// else {
// Navigator.of(context).pop();
Expand All @@ -65,8 80,25 @@ class _TabsScreenState extends State<TabsScreen> {

@override
Widget build(BuildContext context) {
Widget activePage =
CategoriesScreen(onToggleFavorite: _toggleMealFavoriteStatus);
final availableMeals = dummyMeals.where((meal) {
if (_selectedFilters[Filter.glutenFree]! && !meal.isGlutenFree) {
return false;
}
if (_selectedFilters[Filter.lactoseFree]! && !meal.isLactoseFree) {
return false;
}
if (_selectedFilters[Filter.vegetarian]! && !meal.isVegetarian) {
return false;
}
if (_selectedFilters[Filter.vegan]! && !meal.isVegan) {
return false;
}
return true;
}).toList();
Widget activePage = CategoriesScreen(
onToggleFavorite: _toggleMealFavoriteStatus,
availableMeals: availableMeals,
);
var activePageTitle = 'Categories';

if (_selectedPageIndex == 1) {
Expand Down

0 comments on commit d2a6b3c

Please sign in to comment.