You may got this error in Flutter if you haven't placed MaterialApp() widget correctly in widget tree. See the solution below to solve this error:
Error Message:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞════════ No MediaQuery widget ancestor found. MyApp widgets require a MediaQuery widget ancestor. The specific widget that could not find a MediaQuery ancestor was: MyApp The ownership chain for the affected widget is: "MyApp ← [root]"
Solution 1:
class MyApp extends StatelessWidget{ @override Widget build(BuildContext context) { return MaterialApp( //use MaterialApp() widget like this home: Home() //create new widget class for this 'home' to // escape 'No MediaQuery widget found' error ); } }
Solution 2:
MediaQuery( data: MediaQueryData(), child: MaterialApp() )
This answer is referenced from: How to Solve ’No MediaQuery widget found’ Error in Flutter
Top comments (0)