1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-14 11:28:36 +00:00

add dark mode

This commit is contained in:
Eric Windmill
2025-08-06 12:11:30 -04:00
parent d43bd76e6c
commit 8cd1635dec
3 changed files with 66 additions and 14 deletions

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'gallery_home.dart';
@@ -10,11 +11,33 @@ void main() {
runApp(const CupertinoGalleryApp());
}
class CupertinoGalleryApp extends StatelessWidget {
class CupertinoGalleryApp extends StatefulWidget {
const CupertinoGalleryApp({super.key});
@override
State<CupertinoGalleryApp> createState() => _CupertinoGalleryAppState();
}
class _CupertinoGalleryAppState extends State<CupertinoGalleryApp> {
ThemeMode _themeMode = ThemeMode.system;
void _handleThemeChange(bool isDarkMode) {
setState(() {
_themeMode = isDarkMode ? ThemeMode.dark : ThemeMode.light;
});
}
@override
Widget build(BuildContext context) {
return const CupertinoApp(title: 'Cupertino Gallery', home: GalleryHome());
return CupertinoApp(
title: 'Cupertino Gallery',
theme: CupertinoThemeData(
brightness: _themeMode == ThemeMode.dark ? Brightness.dark : Brightness.light,
),
home: GalleryHome(
onThemeChange: _handleThemeChange,
isDarkMode: _themeMode == ThemeMode.dark,
),
);
}
}