Created
June 8, 2023 11:24
-
-
Save rei-codes/0359b20dd9f89c44ff7a01aeef346af4 to your computer and use it in GitHub Desktop.
mediaquery on dartpad
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(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