Hi@akhtar,
You need a MaterialApp or a WidgetsApp around your widget. They provide the media query. When you call .of(context) flutter will always look up the widget tree to find the widget. You can see the below example.
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Title',
theme: kThemeData,
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Container(
child: ...,
);
}
}
To know more about Flutter, join our Flutter APP Development Course today.