The code below throws the exception:
I/flutter (23313): The following assertion was thrown building MyApp(dirty): I/flutter (23313): MediaQuery.of() called with a context that does not contain a MediaQuery. I/flutter (23313): No MediaQuery ancestor could be found starting from the context that was passed to MediaQuery.of(). I/flutter (23313): This can happen because you do not have a WidgetsApp or MaterialApp widget (those widgets introduce I/flutter (23313): a MediaQuery), or it can happen if the context you use comes from a widget above those widgets.
I dont know what is the cause of the error is thrown because the Widget ancestor of the Container is a MaterialApp widget.
Could you help me please?
import 'package:flutter/material.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body:Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child:Text("Hello")
)
)
);
}
}