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,170 points
977 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());
}
answered Sep 3, 2020 by MD
• 95,060 points

Related Questions In Others

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,240 points
507 views
+1 vote
1 answer

what is the difference between error and stderr in Node.js?

Error is an object created by Node.js to handle ...READ MORE

answered Jul 4, 2019 in Others by sunshine
• 1,280 points
441 views
0 votes
1 answer

Error waiting for a debug connection: The log reader stopped unexpectedly

Hi@akhtar, You need to add textDirection in your ...READ MORE

answered Jul 23, 2020 in Others by MD
• 95,060 points
877 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,170 points
134 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,060 points
213 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,060 points
343 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,060 points
513 views