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,230 points
4,811 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: ...,
    );
  }
}

To know more about Flutter, join our Flutter APP Development Course today.

answered Aug 27, 2020 by MD
• 95,440 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
• 63,420 points
1,668 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, 2023 in Others by narikkadan
• 63,420 points
336 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,230 points
891 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,440 points
1,058 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,440 points
1,506 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,440 points
4,938 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,440 points
3,179 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