allscore_app/lib/main.dart

59 lines
1.6 KiB
Dart
Raw Normal View History

2024-12-14 16:44:36 +00:00
import 'package:flutter/material.dart';
2025-01-07 13:38:36 +00:00
import 'package:shared_preferences/shared_preferences.dart';
// Firebase Core
import 'package:firebase_core/firebase_core.dart';
// Firebase Database (필요하다면)
import 'package:firebase_database/firebase_database.dart';
// firebase_options.dart 파일을 import
import 'firebase_options.dart';
import 'views/login/login_page.dart';
import 'views/room/main_page.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Firebase 초기화
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform, // FirebaseOptions 사용
);
2024-12-14 16:44:36 +00:00
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
2025-01-07 13:38:36 +00:00
title: 'ALLSCORE',
2024-12-14 16:44:36 +00:00
theme: ThemeData(
2025-01-07 13:38:36 +00:00
primarySwatch: Colors.blue,
),
home: FutureBuilder<bool>(
future: _checkLoginStatus(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Scaffold(
body: Center(child: CircularProgressIndicator()),
);
} else if (snapshot.hasData && snapshot.data == true) {
return const MainPage();
} else {
return const LoginPage();
}
},
2024-12-14 16:44:36 +00:00
),
);
}
2025-01-07 13:38:36 +00:00
Future<bool> _checkLoginStatus() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
bool autoLogin = prefs.getBool('auto_login') ?? false;
String authToken = prefs.getString('auth_token') ?? '';
return autoLogin && authToken.isNotEmpty;
}
2024-12-14 16:44:36 +00:00
}