Skip to content

Instantly share code, notes, and snippets.

@bradcypert
Created December 24, 2020 22:24
Show Gist options
  • Save bradcypert/01a4b740e5e0a16c8a6c5804f6a299a7 to your computer and use it in GitHub Desktop.
Save bradcypert/01a4b740e5e0a16c8a6c5804f6a299a7 to your computer and use it in GitHub Desktop.
Dart Media Query example
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