0

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

James Z
  • 12,209
  • 10
  • 24
  • 44
Coder10
  • 11
  • 3

2 Answers2

0

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(),
  
      );
    }
  }
Hamza Siddiqui
  • 675
  • 5
  • 12
0

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(),
    );
  }
}
Ananda Pramono
  • 899
  • 1
  • 6
  • 18