import 'package:flutter/material.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'firebase_options.dart'; import 'screen/welcom.dart'; import 'screen/login.dart'; import 'screen/register.dart'; import 'screen/dasboart.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Fermentasi Tempe IoT', theme: ThemeData( useMaterial3: true, colorSchemeSeed: const Color(0xFF4DB6AC), scaffoldBackgroundColor: const Color(0xFFF2F6F6), appBarTheme: const AppBarTheme( centerTitle: true, elevation: 0, ), ), // 🔥 INI PENTING initialRoute: '/', routes: { '/': (context) => const AuthGate(), '/welcome': (context) => const WelcomePage(), '/login': (context) => const LoginPage(), '/register': (context) => const RegisterPage(), '/dashboard': (context) => const DashboardPage(), }, ); } } class AuthGate extends StatelessWidget { const AuthGate({super.key}); @override Widget build(BuildContext context) { return StreamBuilder( stream: FirebaseAuth.instance.authStateChanges(), builder: (context, snapshot) { // LOADING if (snapshot.connectionState == ConnectionState.waiting) { return const Scaffold( body: Center(child: CircularProgressIndicator()), ); } // SUDAH LOGIN if (snapshot.data != null) { return const DashboardPage(); } // BELUM LOGIN return const WelcomePage(); }, ); } }