From e349e6c5d40680fa7ad968220b7aab15a6da0e71 Mon Sep 17 00:00:00 2001 From: Aryan Date: Sat, 17 Jul 2021 01:03:58 +0530 Subject: [PATCH] Added basic code to start flutter fire --- lib/login.dart | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 lib/login.dart diff --git a/lib/login.dart b/lib/login.dart new file mode 100644 index 0000000..477ed26 --- /dev/null +++ b/lib/login.dart @@ -0,0 +1,56 @@ +import 'package:flutter/material.dart'; + +// Import the firebase_core plugin +import 'package:firebase_core/firebase_core.dart'; + +void main() { + WidgetsFlutterBinding.ensureInitialized(); + runApp(App()); +} + +class App extends StatefulWidget { + _AppState createState() => _AppState(); +} + +class _AppState 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 + setState(() { + _error = true; + }); + } + } + + @override + void initState() { + initializeFlutterFire(); + super.initState(); + } + + @override + Widget build(BuildContext context) { + //Show error message if initialization failed + // if(_error) { + // return SomethingWentWrong(); + // } + // + // // Show a loader until FlutterFire is initialized + // if (!_initialized) { + // return Loading(); + // } + + return App(); + } +} \ No newline at end of file