mirror of
https://github.com/kevin-DL/commander_league_flutter.git
synced 2026-01-14 11:44:47 +00:00
Basic Firebase setup
This commit is contained in:
@@ -1,14 +1,59 @@
|
||||
import 'package:commander_league/views/home.dart';
|
||||
import 'package:commander_league/views/loading.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Import the firebase_core plugin
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
// This widget is the root of your application.
|
||||
class MyApp extends StatefulWidget {
|
||||
@override
|
||||
_MyAppState createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
// Set default `_initialized` and `_error` state to false
|
||||
bool _initialized = false;
|
||||
bool _error = false;
|
||||
|
||||
// Define an async function to initialize FlutterFire
|
||||
void initializeFlutterFire() async {
|
||||
try {
|
||||
// Wait for Firebase to initialize and set `_initialized` state to true
|
||||
await Firebase.initializeApp();
|
||||
setState(() {
|
||||
_initialized = true;
|
||||
});
|
||||
} catch (e) {
|
||||
// Set `_error` state to true if Firebase initialization fails
|
||||
print(e);
|
||||
setState(() {
|
||||
_error = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
initializeFlutterFire();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Show error message if initialization failed
|
||||
if (_error) {
|
||||
return Loading();
|
||||
}
|
||||
|
||||
// Show a loader until FlutterFire is initialized
|
||||
if (!_initialized) {
|
||||
return Loading();
|
||||
}
|
||||
|
||||
return MaterialApp(
|
||||
title: 'Commander League',
|
||||
theme: ThemeData(
|
||||
|
||||
14
lib/views/loading.dart
Normal file
14
lib/views/loading.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Loading extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SafeArea(
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user