Created
December 24, 2020 22:24
-
-
Save bradcypert/01a4b740e5e0a16c8a6c5804f6a299a7 to your computer and use it in GitHub Desktop.
Dart Media Query example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Greeting'), | |
), | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
@override | |
Widget build(context) { | |
var query = MediaQuery.of(context); | |
return Container( | |
child: Column( | |
children: [ | |
Text("Width: ${query.size.width}"), | |
Text("Height: ${query.size.height}"), | |
Text("Orientation: ${query.orientation}"), | |
] | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment