Flutter Error MediaQuery of called with a context that does not contain a MediaQuery

0 votes

Hi Guys,

I have been trying to get the size of the whole context view in Flutter. But every time I try I'm getting the below-mentioned error. 

Flutter Error: MediaQuery.of() called with a context that does not contain a MediaQuery.

How can I solve this error?

Aug 27, 2020 in Others by akhtar
• 38,240 points
4,334 views

1 answer to this question.

0 votes

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: ...,
    );
  }
}
answered Aug 27, 2020 by MD
• 95,460 points

Related Questions In Others

0 votes
1 answer

'Microsoft.Office.Interop.Excel.Range' does not contain a definition for 'get_Default'

You are using C# version 4, the ...READ MORE

answered Oct 16, 2022 in Others by narikkadan
• 59,740 points
707 views
0 votes
1 answer

Getting data out of a cell with a #NAME? error in Excel VBA

If you need VBA, use .Formula: Dim f As ...READ MORE

answered Feb 3 in Others by narikkadan
• 59,740 points
58 views
0 votes
1 answer
0 votes
1 answer

What is the future of flutter?

Hi@MD, Flutter is a rather new cross-platform framework ...READ MORE

answered Jul 17, 2020 in Others by akhtar
• 38,240 points
599 views
0 votes
1 answer

What is Flutter?

Hi@akhtar, Flutter is an app SDK for building ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,460 points
796 views
0 votes
1 answer

How to install Flutter in Windows system?

Hi@akhtar, You can follow the below-given steps to ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,460 points
1,183 views
0 votes
1 answer

Row's Children Must Not Contain Any Null Values Flutter Error.

Hi@akhtar, You get this error because in your ...READ MORE

answered Sep 15, 2020 in Others by MD
• 95,460 points
4,206 views
0 votes
1 answer

Dart_LoadScriptFromKernel: The binary program does not contain 'main'.

Hi@akhtar, You need to add the main() function ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,460 points
2,614 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP