Jordan Mckenzie
Jordan Mckenzie

Reputation: 1

not able to use firebase integration in flutter

I am using firebase in flutter application after updating the libraries to the latest version. Below is the code which was previously used but now I am facing error

CODE

void main() {
  FirebaseFirestore.instance.settings(timestampsInSnapshotsEnabled: true).then((_) {
    print("Timestamps enabled in snapshots\n");
  }, onError: (_) {
    print("Error enabling timestamps in snapshots\n");
  });
  runApp(MyApp());
}

ERROR

error: The expression doesn't evaluate to a function, so it can't be invoked.

when I am implementing the above code I get the error, please help me to resolve this

Upvotes: 0

Views: 58

Answers (2)

Rajat Palankar
Rajat Palankar

Reputation: 167

You need to Initialize the Firebase instance before runApp(MyApp());

void main() async{

     WidgetsFlutterBinding.ensureInitialized();
      
     await Firebase.initializeApp();
     //Before running App During load time initialize firebase instance.

     runApp(MyApp());
}

Upvotes: 0

Subhojeet Sahoo
Subhojeet Sahoo

Reputation: 45

Here's a code that should fix it.

    Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

Upvotes: 1

Related Questions