Skip to content

Commit

Permalink
Added basic code to start flutter fire
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryan-Dang committed Jul 16, 2021
1 parent 76d737e commit e349e6c
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib/login.dart
Original file line number Diff line number Diff line change
@@ -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<App> {
// 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();
}
}

0 comments on commit e349e6c

Please sign in to comment.