initial
This commit is contained in:
123
lib/core/theme/app_theme.dart
Normal file
123
lib/core/theme/app_theme.dart
Normal file
@@ -0,0 +1,123 @@
|
||||
import 'package:flex_color_scheme/flex_color_scheme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hiddify/core/theme/theme_prefs.dart';
|
||||
|
||||
// mostly exact copy of flex color scheme 7.1's fabulous 12 theme
|
||||
extension AppTheme on ThemePrefs {
|
||||
ThemeData get light {
|
||||
return FlexThemeData.light(
|
||||
scheme: FlexScheme.indigoM3,
|
||||
surfaceMode: FlexSurfaceMode.highScaffoldLowSurface,
|
||||
useMaterial3: true,
|
||||
swapLegacyOnMaterial3: true,
|
||||
useMaterial3ErrorColors: true,
|
||||
blendLevel: 1,
|
||||
subThemesData: const FlexSubThemesData(
|
||||
useTextTheme: true,
|
||||
useM2StyleDividerInM3: true,
|
||||
elevatedButtonSchemeColor: SchemeColor.onPrimaryContainer,
|
||||
elevatedButtonSecondarySchemeColor: SchemeColor.primaryContainer,
|
||||
outlinedButtonOutlineSchemeColor: SchemeColor.primary,
|
||||
toggleButtonsBorderSchemeColor: SchemeColor.primary,
|
||||
segmentedButtonSchemeColor: SchemeColor.primary,
|
||||
segmentedButtonBorderSchemeColor: SchemeColor.primary,
|
||||
unselectedToggleIsColored: true,
|
||||
sliderValueTinted: true,
|
||||
inputDecoratorSchemeColor: SchemeColor.primary,
|
||||
inputDecoratorBackgroundAlpha: 43,
|
||||
inputDecoratorUnfocusedHasBorder: false,
|
||||
inputDecoratorFocusedBorderWidth: 1.0,
|
||||
inputDecoratorPrefixIconSchemeColor: SchemeColor.primary,
|
||||
popupMenuRadius: 8.0,
|
||||
popupMenuElevation: 3.0,
|
||||
drawerIndicatorSchemeColor: SchemeColor.primary,
|
||||
bottomNavigationBarMutedUnselectedLabel: false,
|
||||
bottomNavigationBarMutedUnselectedIcon: false,
|
||||
menuRadius: 8.0,
|
||||
menuElevation: 3.0,
|
||||
menuBarRadius: 0.0,
|
||||
menuBarElevation: 2.0,
|
||||
menuBarShadowColor: Color(0x00000000),
|
||||
navigationBarSelectedLabelSchemeColor: SchemeColor.primary,
|
||||
navigationBarMutedUnselectedLabel: false,
|
||||
navigationBarSelectedIconSchemeColor: SchemeColor.onPrimary,
|
||||
navigationBarMutedUnselectedIcon: false,
|
||||
navigationBarIndicatorSchemeColor: SchemeColor.primary,
|
||||
navigationBarIndicatorOpacity: 1.00,
|
||||
navigationRailSelectedLabelSchemeColor: SchemeColor.primary,
|
||||
navigationRailMutedUnselectedLabel: false,
|
||||
navigationRailSelectedIconSchemeColor: SchemeColor.onPrimary,
|
||||
navigationRailMutedUnselectedIcon: false,
|
||||
navigationRailIndicatorSchemeColor: SchemeColor.primary,
|
||||
navigationRailIndicatorOpacity: 1.00,
|
||||
navigationRailBackgroundSchemeColor: SchemeColor.surface,
|
||||
),
|
||||
keyColors: const FlexKeyColors(
|
||||
useSecondary: true,
|
||||
useTertiary: true,
|
||||
keepPrimary: true,
|
||||
),
|
||||
tones: FlexTones.jolly(Brightness.light),
|
||||
visualDensity: FlexColorScheme.comfortablePlatformDensity,
|
||||
);
|
||||
}
|
||||
|
||||
ThemeData get dark {
|
||||
return FlexThemeData.dark(
|
||||
scheme: FlexScheme.indigoM3,
|
||||
useMaterial3: true,
|
||||
swapLegacyOnMaterial3: true,
|
||||
useMaterial3ErrorColors: true,
|
||||
darkIsTrueBlack: trueBlack,
|
||||
surfaceMode: FlexSurfaceMode.highScaffoldLowSurface,
|
||||
// blendLevel: 1,
|
||||
subThemesData: const FlexSubThemesData(
|
||||
blendTextTheme: true,
|
||||
useTextTheme: true,
|
||||
useM2StyleDividerInM3: true,
|
||||
elevatedButtonSchemeColor: SchemeColor.onPrimaryContainer,
|
||||
elevatedButtonSecondarySchemeColor: SchemeColor.primaryContainer,
|
||||
outlinedButtonOutlineSchemeColor: SchemeColor.primary,
|
||||
toggleButtonsBorderSchemeColor: SchemeColor.primary,
|
||||
segmentedButtonSchemeColor: SchemeColor.primary,
|
||||
segmentedButtonBorderSchemeColor: SchemeColor.primary,
|
||||
unselectedToggleIsColored: true,
|
||||
sliderValueTinted: true,
|
||||
inputDecoratorSchemeColor: SchemeColor.primary,
|
||||
inputDecoratorBackgroundAlpha: 43,
|
||||
inputDecoratorUnfocusedHasBorder: false,
|
||||
inputDecoratorFocusedBorderWidth: 1.0,
|
||||
inputDecoratorPrefixIconSchemeColor: SchemeColor.primary,
|
||||
popupMenuRadius: 8.0,
|
||||
popupMenuElevation: 3.0,
|
||||
drawerIndicatorSchemeColor: SchemeColor.primary,
|
||||
bottomNavigationBarMutedUnselectedLabel: false,
|
||||
bottomNavigationBarMutedUnselectedIcon: false,
|
||||
menuRadius: 8.0,
|
||||
menuElevation: 3.0,
|
||||
menuBarRadius: 0.0,
|
||||
menuBarElevation: 2.0,
|
||||
menuBarShadowColor: Color(0x00000000),
|
||||
navigationBarSelectedLabelSchemeColor: SchemeColor.primary,
|
||||
navigationBarMutedUnselectedLabel: false,
|
||||
navigationBarSelectedIconSchemeColor: SchemeColor.onPrimary,
|
||||
navigationBarMutedUnselectedIcon: false,
|
||||
navigationBarIndicatorSchemeColor: SchemeColor.primary,
|
||||
navigationBarIndicatorOpacity: 1.00,
|
||||
navigationRailSelectedLabelSchemeColor: SchemeColor.primary,
|
||||
navigationRailMutedUnselectedLabel: false,
|
||||
navigationRailSelectedIconSchemeColor: SchemeColor.onPrimary,
|
||||
navigationRailMutedUnselectedIcon: false,
|
||||
navigationRailIndicatorSchemeColor: SchemeColor.primary,
|
||||
navigationRailIndicatorOpacity: 1.00,
|
||||
navigationRailBackgroundSchemeColor: SchemeColor.surface,
|
||||
),
|
||||
keyColors: const FlexKeyColors(
|
||||
useSecondary: true,
|
||||
useTertiary: true,
|
||||
),
|
||||
// tones: FlexTones.jolly(Brightness.dark),
|
||||
visualDensity: FlexColorScheme.comfortablePlatformDensity,
|
||||
);
|
||||
}
|
||||
}
|
||||
6
lib/core/theme/constants.dart
Normal file
6
lib/core/theme/constants.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
abstract class ConnectionButtonColor {
|
||||
static const connected = Color.fromRGBO(89, 140, 82, 1);
|
||||
static const disconnected = Color.fromRGBO(74, 77, 139, 1);
|
||||
}
|
||||
4
lib/core/theme/theme.dart
Normal file
4
lib/core/theme/theme.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
export 'app_theme.dart';
|
||||
export 'constants.dart';
|
||||
export 'theme_controller.dart';
|
||||
export 'theme_prefs.dart';
|
||||
41
lib/core/theme/theme_controller.dart
Normal file
41
lib/core/theme/theme_controller.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hiddify/core/theme/theme_prefs.dart';
|
||||
import 'package:hiddify/data/data_providers.dart';
|
||||
import 'package:hiddify/utils/utils.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
part 'theme_controller.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class ThemeController extends _$ThemeController with AppLogger {
|
||||
@override
|
||||
ThemePrefs build() {
|
||||
return ThemePrefs(
|
||||
themeMode: ThemeMode.values[_prefs.getInt(_themeModeKey) ?? 0],
|
||||
trueBlack: _prefs.getBool(_trueBlackKey) ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
SharedPreferences get _prefs => ref.read(sharedPreferencesProvider);
|
||||
|
||||
static const _themeModeKey = "theme_mode";
|
||||
static const _trueBlackKey = "true_black";
|
||||
|
||||
Future<void> change({
|
||||
ThemeMode? themeMode,
|
||||
bool? trueBlack,
|
||||
}) async {
|
||||
loggy.debug('changing theme, mode=$themeMode, trueBlack=$trueBlack');
|
||||
if (themeMode != null) {
|
||||
await _prefs.setInt(_themeModeKey, themeMode.index);
|
||||
}
|
||||
if (trueBlack != null) {
|
||||
await _prefs.setBool(_trueBlackKey, trueBlack);
|
||||
}
|
||||
state = state.copyWith(
|
||||
themeMode: themeMode ?? state.themeMode,
|
||||
trueBlack: trueBlack ?? state.trueBlack,
|
||||
);
|
||||
}
|
||||
}
|
||||
14
lib/core/theme/theme_prefs.dart
Normal file
14
lib/core/theme/theme_prefs.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'theme_prefs.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class ThemePrefs with _$ThemePrefs {
|
||||
const ThemePrefs._();
|
||||
|
||||
const factory ThemePrefs({
|
||||
@Default(ThemeMode.system) ThemeMode themeMode,
|
||||
@Default(false) bool trueBlack,
|
||||
}) = _ThemePrefs;
|
||||
}
|
||||
Reference in New Issue
Block a user