|
|
|
@ -6,6 +6,7 @@ import '../home/home_screen.dart';
|
|
|
|
import '../recipes/recipes_screen.dart';
|
|
|
|
import '../recipes/recipes_screen.dart';
|
|
|
|
import '../favourites/favourites_screen.dart';
|
|
|
|
import '../favourites/favourites_screen.dart';
|
|
|
|
import '../bookmarks/bookmarks_screen.dart';
|
|
|
|
import '../bookmarks/bookmarks_screen.dart';
|
|
|
|
|
|
|
|
import '../community/community_screen.dart';
|
|
|
|
import '../session/session_screen.dart';
|
|
|
|
import '../session/session_screen.dart';
|
|
|
|
import 'app_router.dart';
|
|
|
|
import 'app_router.dart';
|
|
|
|
|
|
|
|
|
|
|
|
@ -71,8 +72,9 @@ class MainNavigationScaffoldState extends State<MainNavigationScaffold> {
|
|
|
|
void _onItemTapped(int index) {
|
|
|
|
void _onItemTapped(int index) {
|
|
|
|
final isLoggedIn = _isLoggedIn;
|
|
|
|
final isLoggedIn = _isLoggedIn;
|
|
|
|
|
|
|
|
|
|
|
|
// Only allow navigation to Recipes (1), Favourites (2), and Bookmarks (4) if logged in
|
|
|
|
// Only allow navigation to Recipes (1) and Bookmarks (2) if logged in
|
|
|
|
if (!isLoggedIn && (index == 1 || index == 2 || index == 4)) {
|
|
|
|
// Community (4) and User (3) are always accessible
|
|
|
|
|
|
|
|
if (!isLoggedIn && (index == 1 || index == 2)) {
|
|
|
|
// Redirect to User/Session tab to prompt login
|
|
|
|
// Redirect to User/Session tab to prompt login
|
|
|
|
setState(() {
|
|
|
|
setState(() {
|
|
|
|
_currentIndex = 3; // User/Session tab
|
|
|
|
_currentIndex = 3; // User/Session tab
|
|
|
|
@ -92,6 +94,23 @@ class MainNavigationScaffoldState extends State<MainNavigationScaffold> {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Public method to navigate to Favourites screen (used from Recipes AppBar).
|
|
|
|
|
|
|
|
void navigateToFavourites() {
|
|
|
|
|
|
|
|
final isLoggedIn = _isLoggedIn;
|
|
|
|
|
|
|
|
if (!isLoggedIn) {
|
|
|
|
|
|
|
|
// Redirect to User/Session tab to prompt login
|
|
|
|
|
|
|
|
navigateToUser();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Navigate to Favourites as a full-screen route
|
|
|
|
|
|
|
|
Navigator.push(
|
|
|
|
|
|
|
|
context,
|
|
|
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
|
|
|
builder: (context) => const FavouritesScreen(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _onAddRecipePressed(BuildContext context) async {
|
|
|
|
void _onAddRecipePressed(BuildContext context) async {
|
|
|
|
final isLoggedIn = _isLoggedIn;
|
|
|
|
final isLoggedIn = _isLoggedIn;
|
|
|
|
|
|
|
|
|
|
|
|
@ -134,15 +153,14 @@ class MainNavigationScaffoldState extends State<MainNavigationScaffold> {
|
|
|
|
: const ValueKey('recipes_logged_out'),
|
|
|
|
: const ValueKey('recipes_logged_out'),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
case 2:
|
|
|
|
case 2:
|
|
|
|
// Favourites - only show if logged in, otherwise show login prompt
|
|
|
|
// Bookmarks - only show if logged in
|
|
|
|
// Use a key based on login state to force rebuild when login changes
|
|
|
|
// Use a key based on login state to force rebuild when login changes
|
|
|
|
return FavouritesScreen(key: ValueKey(_isLoggedIn));
|
|
|
|
return BookmarksScreen(key: ValueKey(_isLoggedIn));
|
|
|
|
case 3:
|
|
|
|
case 3:
|
|
|
|
return SessionScreen(onSessionChanged: _onSessionChanged);
|
|
|
|
return SessionScreen(onSessionChanged: _onSessionChanged);
|
|
|
|
case 4:
|
|
|
|
case 4:
|
|
|
|
// Bookmarks - only show if logged in
|
|
|
|
// Community - always accessible
|
|
|
|
// Use a key based on login state to force rebuild when login changes
|
|
|
|
return const CommunityScreen();
|
|
|
|
return BookmarksScreen(key: ValueKey(_isLoggedIn));
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return const SizedBox();
|
|
|
|
return const SizedBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -156,8 +174,9 @@ class MainNavigationScaffoldState extends State<MainNavigationScaffold> {
|
|
|
|
// Check login state in build to trigger rebuilds
|
|
|
|
// Check login state in build to trigger rebuilds
|
|
|
|
_checkLoginState();
|
|
|
|
_checkLoginState();
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure current index is valid (if logged out, don't allow Recipes/Favourites/Bookmarks)
|
|
|
|
// Ensure current index is valid (if logged out, don't allow Recipes/Bookmarks)
|
|
|
|
if (!isLoggedIn && (_currentIndex == 1 || _currentIndex == 2 || _currentIndex == 4)) {
|
|
|
|
// Community (4) and User (3) are always accessible
|
|
|
|
|
|
|
|
if (!isLoggedIn && (_currentIndex == 1 || _currentIndex == 2)) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
if (mounted) {
|
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
|
|
|
setState(() {
|
|
|
|
@ -246,19 +265,18 @@ class MainNavigationScaffoldState extends State<MainNavigationScaffold> {
|
|
|
|
child: Row(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
// Favourites - only show if logged in
|
|
|
|
// Bookmarks - only show if logged in
|
|
|
|
if (isLoggedIn)
|
|
|
|
if (isLoggedIn)
|
|
|
|
_buildNavItem(
|
|
|
|
_buildNavItem(
|
|
|
|
icon: Icons.favorite,
|
|
|
|
icon: Icons.bookmark,
|
|
|
|
label: 'Favourites',
|
|
|
|
label: 'Bookmarks',
|
|
|
|
index: 2,
|
|
|
|
index: 2,
|
|
|
|
onTap: () => _onItemTapped(2),
|
|
|
|
onTap: () => _onItemTapped(2),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
// Bookmarks - only show if logged in
|
|
|
|
// Community - always accessible
|
|
|
|
if (isLoggedIn)
|
|
|
|
|
|
|
|
_buildNavItem(
|
|
|
|
_buildNavItem(
|
|
|
|
icon: Icons.bookmark,
|
|
|
|
icon: Icons.people,
|
|
|
|
label: 'Bookmarks',
|
|
|
|
label: 'Community',
|
|
|
|
index: 4,
|
|
|
|
index: 4,
|
|
|
|
onTap: () => _onItemTapped(4),
|
|
|
|
onTap: () => _onItemTapped(4),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|