DEV Community

Cover image for [Solved] Flutter Error: MediaQuery.of() called with a context that does not contain a MediaQuery - fluttercorner.com
FlutterCorner
FlutterCorner

Posted on

[Solved] Flutter Error: MediaQuery.of() called with a context that does not contain a MediaQuery - fluttercorner.com

Hello Guys how are you all ? Hope you all are fine. When I run my flutter project Suddenly I got Flutter Error: MediaQuery.of() called with a context that does not contain a MediaQuery In Flutter in my stacktrack.

Everything was working fine, But as I use MediaQuery.of(context).size; in my StatelessWidget Or StateFulWidget I am Facing This Above Error.

What is Error ?

When I Try to use MediaQuery.of(context).size; In My StateFul Or StateLess Widget I am Faced Below Error In My Stack Track.

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

Here is my Code.

import 'package:flutter/material.dart';

void main => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    final size = MediaQuery.of(context).size;
    return new MaterialApp(
      home: new Scaffold(
         // Rest of my code
      ),
    );
  }
}
Enter fullscreen mode Exit fullscreen mode

Solutions

Here is All Possible Solution added please visit [Solved] Flutter Error: MediaQuery.of() called with a context that does not contain a MediaQuery

Top comments (0)