Merge branch 'main' of hiddify-github:hiddify/hiddify-next
This commit is contained in:
@@ -33,7 +33,7 @@ class AppView extends HookConsumerWidget with PresLogger {
|
||||
supportedLocales: AppLocaleUtils.supportedLocales,
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
debugShowCheckedModeBanner: false,
|
||||
themeMode: theme.mode,
|
||||
themeMode: theme.mode.flutterThemeMode,
|
||||
theme: theme.light(),
|
||||
darkTheme: theme.dark(),
|
||||
title: Constants.appName,
|
||||
|
||||
@@ -19,6 +19,5 @@ TranslationsEn translations(TranslationsRef ref) =>
|
||||
@Riverpod(keepAlive: true)
|
||||
AppTheme theme(ThemeRef ref) => AppTheme(
|
||||
ref.watch(themeModeNotifierProvider),
|
||||
ref.watch(trueBlackThemeNotifierProvider),
|
||||
ref.watch(localeNotifierProvider).preferredFontFamily,
|
||||
);
|
||||
|
||||
@@ -1,16 +1,38 @@
|
||||
import 'package:flex_color_scheme/flex_color_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hiddify/core/prefs/locale_prefs.dart';
|
||||
|
||||
enum AppThemeMode {
|
||||
system,
|
||||
light,
|
||||
dark,
|
||||
black;
|
||||
|
||||
String present(TranslationsEn t) => switch (this) {
|
||||
system => t.settings.general.themeModes.system,
|
||||
light => t.settings.general.themeModes.light,
|
||||
dark => t.settings.general.themeModes.dark,
|
||||
black => t.settings.general.themeModes.black,
|
||||
};
|
||||
|
||||
ThemeMode get flutterThemeMode => switch (this) {
|
||||
system => ThemeMode.system,
|
||||
light => ThemeMode.light,
|
||||
dark => ThemeMode.dark,
|
||||
black => ThemeMode.dark,
|
||||
};
|
||||
|
||||
bool get trueBlack => this == black;
|
||||
}
|
||||
|
||||
// mostly exact copy of flex color scheme 7.1's fabulous 12 theme
|
||||
class AppTheme {
|
||||
AppTheme(
|
||||
this.mode,
|
||||
this.trueBlack,
|
||||
this.fontFamily,
|
||||
);
|
||||
|
||||
final ThemeMode mode;
|
||||
final bool trueBlack;
|
||||
final AppThemeMode mode;
|
||||
final String fontFamily;
|
||||
|
||||
ThemeData light() {
|
||||
@@ -81,7 +103,7 @@ class AppTheme {
|
||||
useMaterial3: true,
|
||||
swapLegacyOnMaterial3: true,
|
||||
useMaterial3ErrorColors: true,
|
||||
darkIsTrueBlack: trueBlack,
|
||||
darkIsTrueBlack: mode.trueBlack,
|
||||
surfaceMode: FlexSurfaceMode.highScaffoldLowSurface,
|
||||
// blendLevel: 1,
|
||||
subThemesData: const FlexSubThemesData(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hiddify/core/prefs/app_theme.dart';
|
||||
import 'package:hiddify/data/data_providers.dart';
|
||||
import 'package:hiddify/utils/pref_notifier.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
@@ -10,29 +10,15 @@ class ThemeModeNotifier extends _$ThemeModeNotifier {
|
||||
late final _pref = Pref(
|
||||
ref.watch(sharedPreferencesProvider),
|
||||
"theme_mode",
|
||||
ThemeMode.system,
|
||||
mapFrom: ThemeMode.values.byName,
|
||||
AppThemeMode.system,
|
||||
mapFrom: AppThemeMode.values.byName,
|
||||
mapTo: (value) => value.name,
|
||||
);
|
||||
|
||||
@override
|
||||
ThemeMode build() => _pref.getValue();
|
||||
AppThemeMode build() => _pref.getValue();
|
||||
|
||||
Future<void> update(ThemeMode value) {
|
||||
state = value;
|
||||
return _pref.update(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class TrueBlackThemeNotifier extends _$TrueBlackThemeNotifier {
|
||||
late final _pref =
|
||||
Pref(ref.watch(sharedPreferencesProvider), "true_black_theme", false);
|
||||
|
||||
@override
|
||||
bool build() => _pref.getValue();
|
||||
|
||||
Future<void> update(bool value) {
|
||||
Future<void> update(AppThemeMode value) {
|
||||
state = value;
|
||||
return _pref.update(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user