WidgetsFlutterBinding.ensureInitialized() Explained — Why Bindings Are Crucial for Flutter Apps
What is purpose of writing WidgetsFlutterBinding.ensureInitialized() in main() before runApp() ?

WidgetsFlutterBinding is used when you need to interact with Flutter engine before calling runApp(). In simple terms, WidgetsFlutterBinding makes sure that your app level components can successfully communicate with lower level platform services e.g. calling platform specific code (platform channels), async operations, post-frame callback, etc.
It makes sure that Flutter engine is initialized and any code which requires to call native code such as Firebase, will be provided with WidgetsBinding in order to handle native code calls. In addition, it also ensures various aspects of app like async operations, widget tree management, painting and other crucial scheduling tasks.
Now that you have the basic idea, we can dig deeper into what actually is Binding and how it serves the purpose. If you don’t want to go deeper in the concept, you can come back here, when you feel like reading again.
Some Pre-Requisites
You must have come across the architecture of Flutter. If not, take a look below. It depicts 3 main layers: Framework Layer, Engine Layer, Embedder Layer

The Framework layer is what we interact on day to day basis when writing apps including all widgets, service classes which allow to interact with lower engine layers. This layer contains dart code.
The Engine layer has actual implementations that support smooth functioning of the framework layer, like dart VM, skia, platform channels, layout rendering, and much more.
The Embedder layer contains everything related to specific platform.
What Is Binding ?
As the name implies, it binds something. But What? The answer lies in the implementations of BaseBinding class.
PaintingBinding — responsible for binding actual layout painting library.
WidgetBinding — binds the Widget tree to Flutter engine.
RenderBinding — binds the Render tree to Flutter engine.
GestureBinding — for binding gestures subsytem.
SemanticBinding — binding the semantic layer to Flutter engine.
SchedularBinding — binding for animations, tickers, drawFrame callbacks, post-frame callbacks. Used as schedular for immediate tasks such as rebuilding widgets, user input events, running animations, etc.
ServicesBinding — interacting with platform channels, listening to platform messages and directing them to handler via BinaryMessanger.
You must have got a basic idea from the short description of what each binding does. Let’s understand how flutter uses this together to make our app function smoothly
How Is Everything Related ?
Basically, WidgetsFlutterBinding is the implementation of concrete binding that binds the framework to the flutter engine and initializes WidgetBinding instance. It is responsible for app’s lifecycle, handling input gestures, triggering the builds and lay outing of widgets, managing widget tree. It also interacts with native platform and makes use of native platform’s functionalities to make flutter app more performant.
The runApp() method calls this method internally and attaches the root widget root of element tree followed by scheduling a warm up frame.
Conclusion
The WidgetsFlutterBinding class plays fundamental role in Flutter application. It enables the app to leverage native platform’s functionalities improving performance. It’s also responsible for async operations in the app.
From managing the widget tree to lay outing and rendering the tree, it ensure the everything runs smoothly. Hence, understanding WidgetsFlutterBinding class is fundamentally necessary for every Flutter developer. It makes us a good developer when creating more efficient and performant flutter apps.
Hope this article has helped you in some way. Any suggestions are welcomed in the response or on my LinkedIn
Thank You!
More References
https://stackoverflow.com/a/63873689
https://www.dhiwise.com/post/widgetsflutterbinding-the-key-to-efficient-flutter-apps
https://medium.com/@mbixjkee1392/flutter-under-the-hood-binding-2b0ea65e5314