My App get stucked at loading screen after adding Firebase.initializeApp(), without Firebase.initializeApp(), it displays my login screen, but I can't use any of the firebase plugin in my pubspec.yaml file without initializing firebase_core.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: themeData(),
home:Login()
);
}
Tried this,it loads the error screen with the error: future returned null
void main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder(
// Initialize FlutterFire
future: Firebase.initializeApp(),
builder: (context, snapshot) {
// Check for errors
if (snapshot.hasError) {
print(snapshot.error.toString);
return Error();
}
// Once complete, show your application
if (snapshot.connectionState == ConnectionState.done) {
return Login();
}
// Otherwise, show something whilst waiting for initialization to complete
return Loading();
},
);
}
}
pubpec.yaml file
google_sign_in: ^4.5.5
uuid: ^2.2.2
path_provider: ^1.6.21
firebase_storage: ^5.0.0-dev.2
firebase_messaging: ^7.0.3
cloud_firestore: ^0.14.1+3
firebase_auth: ^0.18.1+2
firebase_core: ^0.5.0+1
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[v] Flutter (Channel stable, v1.17.4, on Microsoft Windows [Version 10.0.10240], locale en-US)
[v] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[v] Android Studio (version 3.4)
[v] VS Code (version 1.50.1)
[v] Connected device (1 available)
After updating initiate firebase call in main.dart it worked for me.
Added 'options: DefaultFirebaseOptions.android' inside 'await Firebase.initializeApp(options: DefaultFirebaseOptions.android);'
You can try also try with 'await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);'
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
runApp(LoginPage());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With