import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'screens/auth/login_screen.dart'; import 'screens/home/home_screen.dart'; import 'providers/auth_provider.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); // Initialiser Firebase await Firebase.initializeApp(); // Initialiser Hive for offline støtte await Hive.initFlutter(); runApp( const ProviderScope( child: TimeRegApp(), ), ); } class TimeRegApp extends ConsumerWidget { const TimeRegApp({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final authState = ref.watch(authStateProvider); return MaterialApp( title: 'TimeReg', debugShowCheckedModeBanner: false, theme: ThemeData( colorScheme: ColorScheme.fromSeed( seedColor: Colors.blue, brightness: Brightness.light, ), useMaterial3: true, appBarTheme: const AppBarTheme( centerTitle: true, elevation: 0, ), cardTheme: CardTheme( elevation: 2, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), inputDecorationTheme: InputDecorationTheme( border: OutlineInputBorder( borderRadius: BorderRadius.circular(12), ), filled: true, ), ), darkTheme: ThemeData( colorScheme: ColorScheme.fromSeed( seedColor: Colors.blue, brightness: Brightness.dark, ), useMaterial3: true, appBarTheme: const AppBarTheme( centerTitle: true, elevation: 0, ), cardTheme: CardTheme( elevation: 2, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), inputDecorationTheme: InputDecorationTheme( border: OutlineInputBorder( borderRadius: BorderRadius.circular(12), ), filled: true, ), ), themeMode: ThemeMode.system, home: authState.when( data: (user) { if (user != null) { return const HomeScreen(); } return const LoginScreen(); }, loading: () => const Scaffold( body: Center( child: CircularProgressIndicator(), ), ), error: (error, stack) => Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ const Icon(Icons.error_outline, size: 48, color: Colors.red), const SizedBox(height: 16), Text('Feil: $error'), const SizedBox(height: 16), ElevatedButton( onPressed: () { // Prøv å laste på nytt }, child: const Text('Prøv igjen'), ), ], ), ), ), ), ); } }