[英]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问候
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.