Abschnitt 10
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter_meals/models/meal.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:flutter_meals/models/meal.dart';
|
||||
|
||||
class FavoriteMealsNotifier extends StateNotifier<List<Meal>> {
|
||||
FavoriteMealsNotifier() : super([]);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter_meals/providers/meals_provider.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:flutter_meals/providers/meals_provider.dart';
|
||||
|
||||
enum Filter {
|
||||
glutenFree,
|
||||
lactoseFree,
|
||||
@@ -11,17 +12,18 @@ enum Filter {
|
||||
class FiltersNotifier extends StateNotifier<Map<Filter, bool>> {
|
||||
FiltersNotifier()
|
||||
: super({
|
||||
Filter.glutenFree: false,
|
||||
Filter.lactoseFree: false,
|
||||
Filter.vegetarian: false,
|
||||
Filter.vegan: false
|
||||
});
|
||||
Filter.glutenFree: false,
|
||||
Filter.lactoseFree: false,
|
||||
Filter.vegetarian: false,
|
||||
Filter.vegan: false
|
||||
});
|
||||
|
||||
void setFilters(Map<Filter, bool> chosenFilters) {
|
||||
state = chosenFilters;
|
||||
}
|
||||
|
||||
void setFilter(Filter filter, bool isActive) {
|
||||
// state[filter] = isActive; // not allowed! => mutating state
|
||||
state = {
|
||||
...state,
|
||||
filter: isActive,
|
||||
@@ -30,8 +32,8 @@ class FiltersNotifier extends StateNotifier<Map<Filter, bool>> {
|
||||
}
|
||||
|
||||
final filtersProvider =
|
||||
StateNotifierProvider<FiltersNotifier, Map<Filter, bool>>(
|
||||
(ref) => FiltersNotifier(),
|
||||
StateNotifierProvider<FiltersNotifier, Map<Filter, bool>>(
|
||||
(ref) => FiltersNotifier(),
|
||||
);
|
||||
|
||||
final filteredMealsProvider = Provider((ref) {
|
||||
@@ -53,4 +55,4 @@ final filteredMealsProvider = Provider((ref) {
|
||||
}
|
||||
return true;
|
||||
}).toList();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter_meals/data/dummy_data.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:flutter_meals/data/dummy_data.dart';
|
||||
|
||||
final mealsProvider = Provider((ref) {
|
||||
return dummyMeals;
|
||||
});
|
||||
|
||||
+17
-18
@@ -1,10 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'package:flutter_meals/providers/filters_provider.dart';
|
||||
|
||||
// import 'package:flutter_meals/screens/tabs.dart';
|
||||
// import 'package:flutter_meals/widgets/main_drawer.dart';
|
||||
import 'package:flutter_meals/providers/filters_provider.dart';
|
||||
|
||||
class FiltersScreen extends ConsumerWidget {
|
||||
const FiltersScreen({super.key});
|
||||
@@ -29,14 +28,14 @@ class FiltersScreen extends ConsumerWidget {
|
||||
title: Text(
|
||||
'Gluten-free',
|
||||
style: Theme.of(context).textTheme.titleLarge!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
'Only include gluten-free meals.',
|
||||
style: Theme.of(context).textTheme.labelMedium!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
activeColor: Theme.of(context).colorScheme.tertiary,
|
||||
contentPadding: const EdgeInsets.only(left: 34, right: 22),
|
||||
@@ -51,14 +50,14 @@ class FiltersScreen extends ConsumerWidget {
|
||||
title: Text(
|
||||
'Lactose-free',
|
||||
style: Theme.of(context).textTheme.titleLarge!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
'Only include lactose-free meals.',
|
||||
style: Theme.of(context).textTheme.labelMedium!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
activeColor: Theme.of(context).colorScheme.tertiary,
|
||||
contentPadding: const EdgeInsets.only(left: 34, right: 22),
|
||||
@@ -73,14 +72,14 @@ class FiltersScreen extends ConsumerWidget {
|
||||
title: Text(
|
||||
'Vegetarian',
|
||||
style: Theme.of(context).textTheme.titleLarge!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
'Only include vegetarian meals.',
|
||||
style: Theme.of(context).textTheme.labelMedium!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
activeColor: Theme.of(context).colorScheme.tertiary,
|
||||
contentPadding: const EdgeInsets.only(left: 34, right: 22),
|
||||
@@ -95,14 +94,14 @@ class FiltersScreen extends ConsumerWidget {
|
||||
title: Text(
|
||||
'Vegan',
|
||||
style: Theme.of(context).textTheme.titleLarge!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
'Only include vegan meals.',
|
||||
style: Theme.of(context).textTheme.labelMedium!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
activeColor: Theme.of(context).colorScheme.tertiary,
|
||||
contentPadding: const EdgeInsets.only(left: 34, right: 22),
|
||||
|
||||
@@ -49,25 +49,25 @@ class MealDetailsScreen extends ConsumerWidget {
|
||||
Text(
|
||||
'Ingredients',
|
||||
style: Theme.of(context).textTheme.titleLarge!.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
for (final ingredient in meal.ingredients)
|
||||
Text(
|
||||
ingredient,
|
||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'Steps',
|
||||
style: Theme.of(context).textTheme.titleLarge!.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
for (final step in meal.steps)
|
||||
@@ -80,8 +80,8 @@ class MealDetailsScreen extends ConsumerWidget {
|
||||
step,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
color: Theme.of(context).colorScheme.onBackground,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -54,10 +54,9 @@ class _TabsScreenState extends ConsumerState<TabsScreen> {
|
||||
var activePageTitle = 'Categories';
|
||||
|
||||
if (_selectedPageIndex == 1) {
|
||||
final favoritesMeals = ref.watch(favoriteMealsProvider);
|
||||
|
||||
final favoriteMeals = ref.watch(favoriteMealsProvider);
|
||||
activePage = MealsScreen(
|
||||
meals: favoritesMeals,
|
||||
meals: favoriteMeals,
|
||||
);
|
||||
activePageTitle = 'Your Favorites';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user