I have been trying to get the size of the whole context view in Flutter. But every time I try I\'m getting the above mentioned error. Here\'s my code:
impor
MediaQuery
is used by Scaffold
internal components to layout its children as evident from its source code. Thus, it needs to be wrapped inside a widget which will provide a MediaQuery
, like a MaterialApp
widget, which inherits from WidgetsApp
.
To fix your MediaQuery.of(context) should be inside the Material Widget. Material app -> scaffold -> MediaQuery.of(context)
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Loading Page',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyAppPage(),
);
}
}
More Info:MediaQuery.of() called with a context that does not contain a MediaQuery
In other words, your MediaQuery.of(context) should be inside the Material Widget. Material app -> scaffold -> MediaQuery.of(context)