-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic code to start flutter fire
- Loading branch information
1 parent
76d737e
commit e349e6c
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |