Skip to content

Instantly share code, notes, and snippets.

@rei-codes
Created June 8, 2023 11:24
Show Gist options
  • Save rei-codes/0359b20dd9f89c44ff7a01aeef346af4 to your computer and use it in GitHub Desktop.
Save rei-codes/0359b20dd9f89c44ff7a01aeef346af4 to your computer and use it in GitHub Desktop.
mediaquery on dartpad
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
print('HomePage');
return Scaffold(
appBar: AppBar(),
body: Center(
child: Text(
// OLD (BAD) WAY
MediaQuery.of(context).platformBrightness.name,
// NEW (GREAT) WAY
// MediaQuery.platformBrightnessOf(context).name,
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => const DetailsPage()),
);
},
),
);
}
}
class DetailsPage extends StatelessWidget {
const DetailsPage({super.key});
@override
Widget build(BuildContext context) {
print('DetailsPage');
return Scaffold(
appBar: AppBar(),
body: const Center(
child: Text('resize the page'),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment