51 lines
1.3 KiB
Dart
51 lines
1.3 KiB
Dart
import 'package:coffedryer/page/dashboard_page.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:firebase_core/firebase_core.dart';
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'firebase_options.dart';
|
|
import 'package:coffedryer/page/signup_page.dart';
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
await Firebase.initializeApp(
|
|
options: DefaultFirebaseOptions.currentPlatform,
|
|
);
|
|
|
|
runApp(const MainApp());
|
|
}
|
|
|
|
class MainApp extends StatelessWidget {
|
|
const MainApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
/// CEK STATUS LOGIN USER
|
|
home: StreamBuilder<User?>(
|
|
stream: FirebaseAuth.instance.authStateChanges(),
|
|
builder: (context, snapshot) {
|
|
|
|
/// Loading
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return const Scaffold(
|
|
body: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// Jika user sudah login
|
|
if (snapshot.hasData) {
|
|
return const DashboardPage();
|
|
}
|
|
|
|
/// Jika belum login
|
|
return const SignUpPage();
|
|
},
|
|
),
|
|
);
|
|
}
|
|
} |