168 Start
This commit is contained in:
+31
-2
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_navigation/screens/categories.dart';
|
||||
import 'package:flutter_navigation/screens/meals.dart';
|
||||
|
||||
import '../models/meal.dart';
|
||||
|
||||
class TabsScreen extends StatefulWidget {
|
||||
const TabsScreen({super.key});
|
||||
|
||||
@@ -13,6 +15,28 @@ class TabsScreen extends StatefulWidget {
|
||||
|
||||
class _TabsScreenState extends State<TabsScreen> {
|
||||
int _selectedPageIndex = 0;
|
||||
final List<Meal> _favoriteMeals = [];
|
||||
|
||||
void _showInfoMessage(String message) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message)),
|
||||
);
|
||||
}
|
||||
|
||||
void _toggleMealFavoriteStatus(Meal meal) {
|
||||
final isExisting = _favoriteMeals.contains(meal);
|
||||
|
||||
if (isExisting) {
|
||||
setState(() {
|
||||
_favoriteMeals.remove(meal);
|
||||
_showInfoMessage('Meal is no longer a favorite.');
|
||||
});
|
||||
} else {
|
||||
_favoriteMeals.add(meal);
|
||||
_showInfoMessage('Marked as a favorite.');
|
||||
}
|
||||
}
|
||||
|
||||
void _selectPage(int index) {
|
||||
setState(() {
|
||||
@@ -22,11 +46,16 @@ class _TabsScreenState extends State<TabsScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget activePage = const CategoriesScreen();
|
||||
Widget activePage = CategoriesScreen(
|
||||
onToggleFavorites: _toggleMealFavoriteStatus,
|
||||
);
|
||||
var activePageTitle = 'Categories';
|
||||
|
||||
if (_selectedPageIndex == 1) {
|
||||
activePage = const MealsScreen(meals: []);
|
||||
activePage = MealsScreen(
|
||||
meals: _favoriteMeals,
|
||||
onToggleFavorites: _toggleMealFavoriteStatus,
|
||||
);
|
||||
activePageTitle = 'Your Favorites';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user