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
CodePudding user response:
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(),
);
}
}
CodePudding user response:
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(),
);
}
}