Created
January 24, 2023 23:09
-
-
Save flutterdevrelgists/a96399e5f0ad515e4ac447fc12bbb3da to your computer and use it in GitHub Desktop.
Adaptive UI Talk: Example of handling light mode and dark mode in Material.
This file contains hidden or 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(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
darkTheme: ThemeData(brightness: Brightness.dark), | |
home: Scaffold( | |
appBar: AppBar( | |
title: const Text('Flutter Forward 2023'), | |
), | |
body: const _MyPage(), | |
), | |
); | |
} | |
} | |
class _MyPage extends StatelessWidget { | |
const _MyPage(); | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: Icon( | |
Theme.of(context).brightness == Brightness.light | |
? Icons.light_mode | |
: Icons.dark_mode, | |
size: 100.0, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment