How can I get screen size in Flutter without passing context after the deprecation of MediaQueryData.fromWindow(WidgetsBinding.instance.window)
. The new alternative method recommended by flutter is MediaQueryData.fromView(View.of(context)).size.width
which involves the passing of context.
2
Answers
You shouldn’t need the "screen size" in any location where context is not available.
And you don’t need MediaQuery either. Use LayoutBuilder, which gives you the pixels remaining in your current layout, which is the only number you should be looking at when making layout breakpoint decisions.
The ‘height’ here would return the same value as MediaQuery.of(context).size.height without context: