When and how we use it? How it works?
WidgetsFlutterBinding
WidgetsFlutterBinding class Null safety. A concrete binding for applications based on the Widgets framework. This is the glue that binds the framework to the Flutter engine. When using the widgets framework, this binding, or one that implements the same interfaces, must be used.
ensureInitialized method Null safetyReturns an instance of the binding that implements WidgetsBinding. If no binding has yet been initialized, the WidgetsFlutterBinding class is used to create and initialize one. You only need to call this method if you need the binding to be initialized before calling runApp.
Embedder layer uses the engine layer as a library. It is the start point of a Flutter application when launched. It is written in the platform-specific language and hosts the Flutter engine. Embedder enables communication with the underlying operating system, obtains threads for UI, and provides texture.
You have to use it, in this way:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
https://flutter.dev/docs/resources/architectural-overview#architectural-layers
The WidgetFlutterBinding is used to interact with the Flutter engine. Firebase.initializeApp() needs to call native code to initialize Firebase, and since the plugin needs to use platform channels to call the native code, which is done asynchronously therefore you have to call ensureInitialized() to make sure that you have an instance of the WidgetsBinding.
Answerd By https://stackoverflow.com/users/7015400/peter-haddad
Answer Link https://stackoverflow.com/a/63873689
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With