Flutter MediaQuery
Container(
width: MediaQuery.of(context).size.width,
color: Colors.blue,
child: Text('I cover the whole width of the screen!')
)
Joyful Code
Container(
width: MediaQuery.of(context).size.width,
color: Colors.blue,
child: Text('I cover the whole width of the screen!')
)
Container(
height:MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
color: Colors.blue,
child: Text('I cover the whole width of the screen!')
)
void main() => runApp(App());
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Title',
theme: kThemeData,
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Container(
child: ...,
);
}
}