From 85d049d1ffb98c72389627b1d9909af8ff15bb07 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sun, 1 Sep 2024 19:02:18 +0800 Subject: [PATCH] fix: theme mode --- lib/main.dart | 1 + lib/utils/storage.dart | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/main.dart b/lib/main.dart index d8e0eb90..ea4ee983 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -227,6 +227,7 @@ class MyApp extends StatelessWidget { refreshBackgroundColor: darkColorScheme.onSecondary, ), ), + themeMode: GStorage.themeMode, localizationsDelegates: const [ GlobalCupertinoLocalizations.delegate, GlobalMaterialLocalizations.delegate, diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index f109255d..3808d238 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'dart:ui'; import 'package:PiliPalaX/models/common/theme_type.dart'; +import 'package:flutter/material.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:path_provider/path_provider.dart'; import 'package:PiliPalaX/models/model_owner.dart'; @@ -16,6 +17,19 @@ class GStorage { static late final Box setting; static late final Box video; + static ThemeMode get themeMode { + switch (setting.get(SettingBoxKey.themeMode, + defaultValue: ThemeType.system.code)) { + case 0: + return ThemeMode.light; + case 1: + return ThemeMode.dark; + case 2: + default: + return ThemeMode.system; + } + } + static Brightness get brightness { switch (setting.get(SettingBoxKey.themeMode, defaultValue: ThemeType.system.code)) {