58 lines
1.5 KiB
Dart
58 lines
1.5 KiB
Dart
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'firebase_options.dart';
|
|
import 'screens/auth/auth_screen.dart';
|
|
import 'screens/firebase_setup_required_screen.dart';
|
|
import 'screens/home/auftraege_home_screen.dart';
|
|
import 'theme/app_theme.dart';
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
try {
|
|
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
|
|
} catch (e, st) {
|
|
debugPrint('Firebase init failed: $e\n$st');
|
|
runApp(FirebaseSetupRequiredScreen(error: e));
|
|
return;
|
|
}
|
|
runApp(const HandwerksApp());
|
|
}
|
|
|
|
class HandwerksApp extends StatelessWidget {
|
|
const HandwerksApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Handwerksapp',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: AppTheme.light(),
|
|
home: const _AuthGate(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AuthGate extends StatelessWidget {
|
|
const _AuthGate();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return StreamBuilder<User?>(
|
|
stream: FirebaseAuth.instance.authStateChanges(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Scaffold(
|
|
body: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
if (snapshot.hasData) {
|
|
return const AuftraegeHomeScreen();
|
|
}
|
|
return const AuthScreen();
|
|
},
|
|
);
|
|
}
|
|
}
|