import "dart:async"; import "package:flutter/material.dart"; import "package:provider/provider.dart"; import "../app/app_router.dart"; import "../app/app_state.dart"; import "../services/api.dart"; import "../services/auth_storage.dart"; class SplashScreen extends StatefulWidget { const SplashScreen({super.key}); @override State createState() => _SplashScreenState(); } class _SplashScreenState extends State { Timer? _timer; @override void initState() { super.initState(); _timer = Timer(const Duration(milliseconds: 2400), () async { if (!mounted) return; // Check for saved authentication credentials final credentials = await AuthStorage.loadAuth(); if (credentials != null) { // Restore authentication state Api.setAuthToken(credentials.token); final appState = context.read(); appState.setUserId(credentials.userId); } if (!mounted) return; // Always go to beacon scan first - allows browsing without login Navigator.of(context).pushReplacementNamed(AppRoutes.beaconScan); }); } @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, ), ), ), ); } }