This commit is contained in:
Phuoc Nguyen
2025-10-21 16:45:52 +07:00
parent 9c20a44a04
commit 30c245b401
3 changed files with 168 additions and 16 deletions

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/auth_provider.dart';
import '../pages/login_page.dart';
import 'splash_screen.dart';
/// Wrapper widget that checks authentication status
/// Shows login page if not authenticated, otherwise shows child widget
@@ -16,21 +17,27 @@ class AuthWrapper extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final authState = ref.watch(authProvider);
print('AuthWrapper build: isAuthenticated=${authState.isAuthenticated}, isLoading=${authState.isLoading}');
// Show loading indicator while checking auth status
print('AuthWrapper build: isAuthenticated=${authState.isAuthenticated}, isLoading=${authState.isLoading}');
// Show splash screen while checking auth status
if (authState.isLoading && authState.user == null) {
return const Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
return const SplashScreen();
}
// Show child widget if authenticated, otherwise show login page
if (authState.isAuthenticated) {
return child;
} else {
return const LoginPage();
}
// Smooth fade transition between screens
return AnimatedSwitcher(
duration: const Duration(milliseconds: 400),
switchInCurve: Curves.easeInOut,
switchOutCurve: Curves.easeInOut,
child: authState.isAuthenticated
? KeyedSubtree(
key: const ValueKey('main_app'),
child: child,
)
: const KeyedSubtree(
key: ValueKey('login_page'),
child: LoginPage(),
),
);
}
}