payfrit-app/lib/screens/splash_screen.dart
John Mizerek 33f7128b40 feat: implement user authentication with login screen
- Add LoginScreen with form validation and error handling
- Add Api.login() method with LoginResponse model
- Add login route to AppRouter
- Update SplashScreen to check auth status and route to login if needed
- Store auth token in Api service for authenticated requests
- Fix restaurant selection to work with authenticated users
2025-12-29 10:01:35 -08:00

59 lines
1.3 KiB
Dart

import "dart:async";
import "package:flutter/material.dart";
import "package:provider/provider.dart";
import "../app/app_router.dart";
import "../app/app_state.dart";
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
State<SplashScreen> createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
Timer? _timer;
@override
void initState() {
super.initState();
_timer = Timer(const Duration(milliseconds: 2400), () {
if (!mounted) return;
final appState = context.read<AppState>();
// Navigate based on authentication status
if (appState.isLoggedIn) {
Navigator.of(context).pushReplacementNamed(AppRoutes.restaurantSelect);
} else {
Navigator.of(context).pushReplacementNamed(AppRoutes.login);
}
});
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return const Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Text(
"PAYFRIT",
style: TextStyle(
color: Colors.white,
fontSize: 38,
fontWeight: FontWeight.w800,
letterSpacing: 3,
),
),
),
);
}
}