skip to Main Content

I am new to flutter, BUILT an app showing graphs in flutter. When i run the code a red screen is appearing showing the above error

No MediaQuery widget ancestor found. Scaffold widgets require a MediaQuery widget ancestor.

I have cleared all the errors except this one.

Full link of the code

link of screenshot error

2

Answers


  1. Wrap your scaffold to MatertialApp or you can make a class and in that class call GraphScreen like this

       void main() => runApp(const MyApp());
     
      class MyApp extends StatelessWidget {      
        @override
        Widget build(BuildContext context) {
          return MaterialApp(
      
            title: 'Flutter Demo',
            theme: ThemeData(
              primarySwatch: Colors.blue,
            ),
            home: GraphScreen(),
      
          );
        }
      }
    
    Login or Signup to reply.
  2. Check you main.dart, and in the MyApp (Or whatever you named it) class, you should wrap it with MaterialApp. It should fix the problem.

    class MyApp extends StatelessWidget  {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Graphn',
          home: GraphScreen(),
        );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search