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 StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { // 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( // This is the theme of your application. // // Try running your application with "flutter run". You'll see the // application has a blue toolbar. Then, without quitting the app, try // changing the primarySwatch below to Colors.green and then invoke // "hot reload" (press "r" in the console where you ran "flutter run", // or simply save your changes to "hot reload" in a Flutter IDE). // Notice that the counter didn't reset back to zero; the application // is not restarted. primarySwatch: Colors.blue, // This makes the visual density adapt to the platform that you run // the app on. For desktop platforms, the controls will be smaller and // closer together (more dense) than on mobile platforms. visualDensity: VisualDensity.adaptivePlatformDensity, ), home: Home(title: 'Commander League Home Page'), ); } }