import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:logger/logger.dart'; import 'pages/login.dart'; import 'pages/home.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Ping Pong Tracker', theme: ThemeData.dark(useMaterial3: true).copyWith( colorScheme: ColorScheme.dark( primary: Colors.blue.shade800, ), ), home: EntryPoint(), ); } } class EntryPoint extends StatelessWidget { final Logger _logger = Logger(); Future _getInitialPage() async { _logger.d("Fetching token from SharedPreferences"); final prefs = await SharedPreferences.getInstance(); final token = prefs.getString('token'); _logger.d("Token value from SharedPreferences: $token"); if (token == null || token.isEmpty) { _logger.d("No token found. Returning LoginPage."); return LoginPage(); } else { _logger.d("Token found. Returning HomePage."); return HomePage(); } } @override Widget build(BuildContext context) { _logger.d("Building EntryPoint UI with FutureBuilder"); return FutureBuilder( future: _getInitialPage(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { _logger.d("Waiting for initial page resolution."); return const Scaffold( body: Center(child: CircularProgressIndicator()), ); } else if (snapshot.hasError) { _logger.e("Error while resolving initial page: ${snapshot.error}"); return LoginPage(); // Fallback to LoginPage on error } else { _logger.d("Navigation target resolved: ${snapshot.data.runtimeType}"); return snapshot.data!; } }, ); } }