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:
@@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user