Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter app shows a blank screen after integrating Firebase

the app still only shows a blank screen. Here is my main app code:

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';

void main() async {
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('Firebase Integration')),
        body: Center(child: Text('Hello, Firebase!')),
      ),
    );
  }
}

Any help or suggestions would be greatly appreciated!


1 Answers

It looks like you're missing WidgetsFlutterBinding.ensureInitialized(); before initializing Firebase:

void main() async {
  WidgetsFlutterBinding.ensureInitialized(); // Add this line
  await Firebase.initializeApp();
  runApp(MyApp());
}
like image 184
Touseef khattak Avatar answered Jan 25 '26 10:01

Touseef khattak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!