简体   繁体   English

未找到 MediaQuery 小部件祖先。 Scaffold 小部件需要 MediaQuery 小部件祖先

[英]No MediaQuery widget ancestor found. Scaffold widgets require a MediaQuery widget ancestor

I am new to flutter, BUILT an app showing graphs in flutter.我是 flutter 的新手,在 flutter 中构建了一个显示图表的应用程序。 When i run the code a red screen is appearing showing the above error 'No MediaQuery widget ancestor found.当我运行代码时,会出现一个红色屏幕,显示上述错误“未找到 MediaQuery 小部件祖先。 Scaffold widgets require a MediaQuery widget ancestor.' Scaffold 小部件需要 MediaQuery 小部件祖先。 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将您的脚手架包装到 MaterialApp 或者您可以制作一个 class 并在其中 class 像这样调用 GraphScreen

   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.检查你的main.dart和 MyApp(或任何你命名的)class,你应该用 MaterialApp 包装它。 It should fix the problem.它应该可以解决问题。

class MyApp extends StatelessWidget  {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Graphn',
      home: GraphScreen(),
    );
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter:未找到 MediaQuery 小部件祖先 - Flutter: No MediaQuery widget ancestor found 找不到方向性小部件。 RichText小部件需要Directionality小部件祖先 - No Directionality widget found. RichText widgets require a Directionality widget ancestor 未找到材料小部件文本字段小部件需要材料小部件祖先 - No material widget found textfield widgets require a material widget ancestor 未找到 MaterialLocalizations - MyApp 小部件需要由 Localizations 小部件祖先提供的 MaterialLocalizations - No MaterialLocalizations found - MyApp widgets require MaterialLocalizations to be provided by a Localizations widget ancestor 未处理的异常:未找到 MediaQuery 小部件 - 颤动 ShowModalButtonSheet - Unhandled Exception: No MediaQuery widget found - flutter ShowModalButtonSheet 手势捕获的颤振异常。 在 showModalBottomSheet 中找不到 MediaQuery 小部件 - Flutter Exception caught by gesture. No MediaQuery widget found inside showModalBottomSheet 小部件如何使其祖先集中精力? - How can a widget make its ancestor focused? Flutter:在无状态小部件中“查找已停用小部件的祖先是不安全的” - Flutter: “Looking up a deactivated widget's ancestor is unsafe” in a Stateless Widget Flutter:查找已停用小部件的祖先是不安全的 - Flutter: Looking up a deactivated widget's ancestor is unsafe 警报对话框:查找已停用小部件的祖先是不安全的 - Alert Dialogs: Looking up a deactivated widget's ancestor is unsafe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM