简体   繁体   中英

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

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 erros except this one. Kindly help me fix this. The link of the code is attached below along with a Screenshot of error.

Regards

Full link of the code

link of screenshot error

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(),
  
      );
    }
  }

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(),
    );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM