ERROR flutter lib ui ui dart state cc 157 Unhandled Exception ServicesBinding defaultBinaryMessenger was accessed before the binding was initialized

0 votes

Hi Guys,

I have created one table in the Firestore database. I am trying to connect to this database from my flutter app. But it is showing me the below error.

E/flutter ( 8298): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.
E/flutter ( 8298): If you're running an application and need to access the binary messenger before `runApp()` has been called (for example, during plugin initialization), then you need to explicitly call the `WidgetsFlutterBinding.ensureInitialized()` first.
E/flutter ( 8298): If you're running a test, you can call the `TestWidgetsFlutterBinding.ensureInitialized()` as the first line in your test's `main()` method to initialize the binding.
Sep 3, 2020 in Others by akhtar
• 38,260 points
3,489 views

1 answer to this question.

0 votes

Hi@akhtar,

This problem is introduced when you upgrade Flutter. The reason behind this is you are waiting for some data or running an async function inside main(). I was initializing ScopedModel inside main() and inside that, I was waiting for some data. There is a very small fix to avoid this error. You have to initialize this module WidgetsFlutterBinding.ensureInitialized() inside void main() function, before you do runApp() as shown below.

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  Firebase.initializeApp();
  runApp(Mydb());
}

To know more about Flutter, join our Flutter Course today.

answered Sep 3, 2020 by MD
• 95,460 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

"The underlying connection was closed: An unexpected error occurred on a send." With SSL Certificate

The solution for this for me was ...READ MORE

answered Feb 18, 2022 in Others by Rahul
• 9,680 points
11,411 views
0 votes
1 answer

Using unserialize in PHP throws the same error repeatedly

I googled 'Node no longer exists', and ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,250 points
1,597 views
0 votes
1 answer

What is the future of flutter?

Hi@MD, Flutter is a rather new cross-platform framework ...READ MORE

answered Jul 17, 2020 in Others by akhtar
• 38,260 points
1,155 views
0 votes
1 answer

What is Flutter?

Hi@akhtar, Flutter is an app SDK for building ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,460 points
1,458 views
0 votes
1 answer

How to install Flutter in Windows system?

Hi@akhtar, You can follow the below-given steps to ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,460 points
1,786 views
0 votes
1 answer

How to check the connected device name in Flutter?

Hi@akhtar, Flutter has its command own command to ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,460 points
8,164 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP