Skip to content

Instantly share code, notes, and snippets.

@flutterdevrelgists
Created January 24, 2023 23:09
Show Gist options
  • Save flutterdevrelgists/a96399e5f0ad515e4ac447fc12bbb3da to your computer and use it in GitHub Desktop.
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.
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