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.
The 'height' here would return the same value as MediaQuery.of(context).size.height without context:
final double physicalHeight = WidgetsBinding.instance.platformDispatcher.views.first.physicalSize.height;
final double devicePixelRatio =
WidgetsBinding.instance.platformDispatcher.views.first.devicePixelRatio;
final double height = physicalHeight / devicePixelRatio;