Error when connect to firebase

when I try to connect to firebase I add this code to my main.dart

Future main() async {

WidgetsFlutterBinding.ensureInitialized();

await Firebase.initializeApp();

runApp(const MyApp());

}

my app run with white page and give this error

options != null
“FirebaseOptions cannot be null when creating the default app.”

can you advice please

I searched google , I found the best soluation to change my code to become like this

Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: FirebaseOptions(
apiKey: “XXX”, // Your apiKey
appId: “XXX”, // Your appId
messagingSenderId: “XXX”, // Your messagingSenderId
projectId: “XXX”, // Your projectId
),
);
runApp(const MyApp());
}

this is the only thing run my app very well

You need to follow the following steps to fix this:

Delete the google-services.json file from your project.
From the build.gradle file, remove the classpath ‘com.google.gms:google-services:x.x.x’ line.
In the application level build.gradle file, i.e. the build.gradle file inside app folder, remove id ‘com.google.gms.google-services’ from the plugins{} block. Also remove any implementation of Firebase from the dependencies block. For example, if you have implementation ‘com.google.firebase:firebase-database-ktx:x.x.x’ for firebase database, remove it.
Invalidate the cache and restart Android Studio. To do that, open Android studio, click on File and click on Invalidate cache/restart option to restart Android studio.
Android studio invalidate cache/restart

Once it is done, connect to firebase again from Firebase assistant window. Click on Tools in the Android studio menu and click on Firebase to open the assistant window.

Firebase assistant android studio

You can login to the new Firebase account from this window and it will connect your project with the new account. You can restore all dependencies of Firebase once it is connected to the new account. It also downloads the firebase .json file and adds all firebase related configs in the build.gradle files.

This may help you,
Rachel Gomez