Files
Sage/lib/features/authentication/presentation/pages/splash_page.dart
Dani B 2f9ea1a0e8 feat: Complete Phase 1 Authentication and setup Flutter project structure
- Completed authentication system with signup, login, password reset, and logout
- Enhanced error handling and accessibility across all auth flows
- Added comprehensive loading states and user feedback
- Implemented confirmation dialogs for destructive actions
- Setup complete Flutter project structure with proper configuration
- Added planning documentation for Phase 2 household creation
- All Phase 1 success criteria verified and complete
2026-01-28 22:58:09 -05:00

138 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:go_router/go_router.dart';
/// Splash page for initial loading and authentication state checking
///
/// Shows loading indicator while checking authentication state
/// and redirects to appropriate screen based on auth status
class SplashPage extends StatefulWidget {
const SplashPage({super.key});
@override
State<SplashPage> createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
@override
void initState() {
super.initState();
_checkAuthState();
}
/// Check authentication state and navigate accordingly
Future<void> _checkAuthState() async {
try {
// Add small delay for better UX - shows splash screen
await Future.delayed(const Duration(milliseconds: 1500));
if (!mounted) return;
// Check current authentication state
final currentUser = Supabase.instance.client.auth.currentUser;
if (currentUser != null) {
// User is authenticated, navigate to home
if (mounted) {
context.go('/home');
}
} else {
// User is not authenticated, navigate to login
if (mounted) {
context.go('/login');
}
}
} catch (e) {
// Handle authentication state check errors
debugPrint('Error checking auth state: $e');
if (!mounted) return;
// On error, navigate to login for safety
if (mounted) {
context.go('/login');
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// App logo/icon
Container(
width: 120,
height: 120,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
borderRadius: BorderRadius.circular(24),
boxShadow: [
BoxShadow(
color: Theme.of(context).colorScheme.primary.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: const Icon(
Icons.inventory_2_outlined,
size: 60,
color: Colors.white,
),
),
const SizedBox(height: 32),
// App name
Text(
'Sage',
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
const SizedBox(height: 8),
// Tagline
Text(
'Your Food Inventory Tracker',
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
),
const SizedBox(height: 48),
// Loading indicator
Column(
children: [
SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context).colorScheme.primary,
),
),
),
const SizedBox(height: 16),
Text(
'Loading...',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
),
),
],
),
],
),
),
);
}
}