Getting the screen size without the build context is simple in flutter apps.
Use WidgetsBinding to get the screen size without the build context. The complete Code is Given Below.
Mostly we use the Media query to get screen size in the flutter application But this short arrival Covers how to get screen size without context
Get Screen size without Build Context:
we can use the WidgetsBinding instance to get the height and the width of the screen
- Make Size Variable “screenSize”
- Add Value using WidgetBinding.instance.window.physiclSize’
- Now screenSize.width, screenSize.height will give you values
- Full Code Below
Size screenSize = WidgetsBinding.instance.window.physicalSize; double width = screenSize.width; double height = screenSize.height;
With Build Context:
double width = MediaQuery.of(context).size.width; double height = MediaQuery.of(context).size.height;
This above code is responsible for getting high and width of the screen with the context.
This will solve your matter of getting Screen Size without the build context.
For more Flutter tutorials, Tips, Tricks, Free code, Questions, and Error Solving.