Files

126 lines
3.4 KiB
Dart

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 'services/sync_service.dart';
import 'providers/time_provider.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();
// Initialiser SyncService
final syncService = SyncService();
await syncService.init();
runApp(
ProviderScope(
overrides: [
syncServiceProvider.overrideWithValue(syncService),
],
child: const 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: CardThemeData(
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: CardThemeData(
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'),
),
],
),
),
),
),
);
}
}