mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-02-16 06:19:35 +00:00
123
This commit is contained in:
parent
edd5a01482
commit
eef72c6aa6
13 changed files with 1341 additions and 1012 deletions
|
|
@ -5,6 +5,9 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:material_color_utilities/material_color_utilities.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:vaani/features/settings/app_settings_provider.dart';
|
||||
import 'package:vaani/theme/providers/theme_from_cover_provider.dart';
|
||||
import 'package:vaani/theme/theme.dart';
|
||||
|
||||
part 'system_theme_provider.g.dart';
|
||||
|
||||
|
|
@ -72,3 +75,82 @@ FutureOr<(ColorScheme light, ColorScheme dark)?> systemTheme(
|
|||
}
|
||||
return (schemeLight, schemeDark);
|
||||
}
|
||||
|
||||
@riverpod
|
||||
(ThemeData light, ThemeData dark) currentTheme(
|
||||
Ref ref, {
|
||||
bool highContrast = false,
|
||||
String? id,
|
||||
}) {
|
||||
final themeSettings =
|
||||
ref.watch(appSettingsProvider.select((v) => v.themeSettings));
|
||||
ColorScheme lightColorScheme = brandLightColorScheme;
|
||||
ColorScheme darkColorScheme = brandDarkColorScheme;
|
||||
|
||||
final shouldUseHighContrast = themeSettings.highContrast || highContrast;
|
||||
|
||||
if (shouldUseHighContrast) {
|
||||
lightColorScheme = lightColorScheme.copyWith(
|
||||
surface: Colors.white,
|
||||
);
|
||||
darkColorScheme = darkColorScheme.copyWith(
|
||||
surface: Colors.black,
|
||||
);
|
||||
}
|
||||
|
||||
if (themeSettings.useMaterialThemeFromSystem) {
|
||||
var themes =
|
||||
ref.watch(systemThemeProvider(highContrast: shouldUseHighContrast));
|
||||
if (themes.valueOrNull != null) {
|
||||
lightColorScheme = themes.valueOrNull!.$1;
|
||||
darkColorScheme = themes.valueOrNull!.$2;
|
||||
}
|
||||
}
|
||||
|
||||
if (themeSettings.useCurrentPlayerThemeThroughoutApp) {
|
||||
try {
|
||||
if (id != null) {
|
||||
final themeLight = ref.watch(
|
||||
themeOfLibraryItemProvider(
|
||||
id,
|
||||
highContrast: shouldUseHighContrast,
|
||||
brightness: Brightness.light,
|
||||
),
|
||||
);
|
||||
final themeDark = ref.watch(
|
||||
themeOfLibraryItemProvider(
|
||||
id,
|
||||
highContrast: shouldUseHighContrast,
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
);
|
||||
if (themeLight.valueOrNull != null && themeDark.valueOrNull != null) {
|
||||
lightColorScheme = themeLight.valueOrNull!;
|
||||
darkColorScheme = themeDark.valueOrNull!;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrintStack(stackTrace: StackTrace.current, label: e.toString());
|
||||
_logger.severe('not building with player theme');
|
||||
_logger.severe(e.toString());
|
||||
}
|
||||
}
|
||||
final appThemeLight = ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: lightColorScheme.harmonized(),
|
||||
fontFamily: fontFamilyPlatform,
|
||||
textTheme: textTheme,
|
||||
);
|
||||
final appThemeDark = ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: darkColorScheme.harmonized(),
|
||||
fontFamily: fontFamilyPlatform,
|
||||
textTheme: textTheme,
|
||||
brightness: Brightness.dark,
|
||||
// TODO bottom sheet theme is not working
|
||||
bottomSheetTheme: BottomSheetThemeData(
|
||||
backgroundColor: darkColorScheme.surface,
|
||||
),
|
||||
);
|
||||
return (appThemeLight, appThemeDark);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,5 +175,156 @@ class _SystemThemeProviderElement
|
|||
@override
|
||||
bool get highContrast => (origin as SystemThemeProvider).highContrast;
|
||||
}
|
||||
|
||||
String _$currentThemeHash() => r'0e62a7f1b62c6ad73a3769909607407d41eb0338';
|
||||
|
||||
/// See also [currentTheme].
|
||||
@ProviderFor(currentTheme)
|
||||
const currentThemeProvider = CurrentThemeFamily();
|
||||
|
||||
/// See also [currentTheme].
|
||||
class CurrentThemeFamily extends Family<(ThemeData light, ThemeData dark)> {
|
||||
/// See also [currentTheme].
|
||||
const CurrentThemeFamily();
|
||||
|
||||
/// See also [currentTheme].
|
||||
CurrentThemeProvider call({
|
||||
bool highContrast = false,
|
||||
String? id,
|
||||
}) {
|
||||
return CurrentThemeProvider(
|
||||
highContrast: highContrast,
|
||||
id: id,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
CurrentThemeProvider getProviderOverride(
|
||||
covariant CurrentThemeProvider provider,
|
||||
) {
|
||||
return call(
|
||||
highContrast: provider.highContrast,
|
||||
id: provider.id,
|
||||
);
|
||||
}
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _dependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get dependencies => _dependencies;
|
||||
|
||||
static const Iterable<ProviderOrFamily>? _allTransitiveDependencies = null;
|
||||
|
||||
@override
|
||||
Iterable<ProviderOrFamily>? get allTransitiveDependencies =>
|
||||
_allTransitiveDependencies;
|
||||
|
||||
@override
|
||||
String? get name => r'currentThemeProvider';
|
||||
}
|
||||
|
||||
/// See also [currentTheme].
|
||||
class CurrentThemeProvider
|
||||
extends AutoDisposeProvider<(ThemeData light, ThemeData dark)> {
|
||||
/// See also [currentTheme].
|
||||
CurrentThemeProvider({
|
||||
bool highContrast = false,
|
||||
String? id,
|
||||
}) : this._internal(
|
||||
(ref) => currentTheme(
|
||||
ref as CurrentThemeRef,
|
||||
highContrast: highContrast,
|
||||
id: id,
|
||||
),
|
||||
from: currentThemeProvider,
|
||||
name: r'currentThemeProvider',
|
||||
debugGetCreateSourceHash:
|
||||
const bool.fromEnvironment('dart.vm.product')
|
||||
? null
|
||||
: _$currentThemeHash,
|
||||
dependencies: CurrentThemeFamily._dependencies,
|
||||
allTransitiveDependencies:
|
||||
CurrentThemeFamily._allTransitiveDependencies,
|
||||
highContrast: highContrast,
|
||||
id: id,
|
||||
);
|
||||
|
||||
CurrentThemeProvider._internal(
|
||||
super._createNotifier, {
|
||||
required super.name,
|
||||
required super.dependencies,
|
||||
required super.allTransitiveDependencies,
|
||||
required super.debugGetCreateSourceHash,
|
||||
required super.from,
|
||||
required this.highContrast,
|
||||
required this.id,
|
||||
}) : super.internal();
|
||||
|
||||
final bool highContrast;
|
||||
final String? id;
|
||||
|
||||
@override
|
||||
Override overrideWith(
|
||||
(ThemeData light, ThemeData dark) Function(CurrentThemeRef provider) create,
|
||||
) {
|
||||
return ProviderOverride(
|
||||
origin: this,
|
||||
override: CurrentThemeProvider._internal(
|
||||
(ref) => create(ref as CurrentThemeRef),
|
||||
from: from,
|
||||
name: null,
|
||||
dependencies: null,
|
||||
allTransitiveDependencies: null,
|
||||
debugGetCreateSourceHash: null,
|
||||
highContrast: highContrast,
|
||||
id: id,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AutoDisposeProviderElement<(ThemeData light, ThemeData dark)>
|
||||
createElement() {
|
||||
return _CurrentThemeProviderElement(this);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is CurrentThemeProvider &&
|
||||
other.highContrast == highContrast &&
|
||||
other.id == id;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
var hash = _SystemHash.combine(0, runtimeType.hashCode);
|
||||
hash = _SystemHash.combine(hash, highContrast.hashCode);
|
||||
hash = _SystemHash.combine(hash, id.hashCode);
|
||||
|
||||
return _SystemHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated('Will be removed in 3.0. Use Ref instead')
|
||||
// ignore: unused_element
|
||||
mixin CurrentThemeRef
|
||||
on AutoDisposeProviderRef<(ThemeData light, ThemeData dark)> {
|
||||
/// The parameter `highContrast` of this provider.
|
||||
bool get highContrast;
|
||||
|
||||
/// The parameter `id` of this provider.
|
||||
String? get id;
|
||||
}
|
||||
|
||||
class _CurrentThemeProviderElement
|
||||
extends AutoDisposeProviderElement<(ThemeData light, ThemeData dark)>
|
||||
with CurrentThemeRef {
|
||||
_CurrentThemeProviderElement(super.provider);
|
||||
|
||||
@override
|
||||
bool get highContrast => (origin as CurrentThemeProvider).highContrast;
|
||||
@override
|
||||
String? get id => (origin as CurrentThemeProvider).id;
|
||||
}
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package
|
||||
|
|
|
|||
|
|
@ -30,3 +30,190 @@ String get fontFamilyPlatform {
|
|||
return 'Arial'; // 其他平台回退
|
||||
}
|
||||
}
|
||||
|
||||
// letterSpacing 字间距
|
||||
const defaultTextTheme = TextTheme(
|
||||
displayLarge: TextStyle(
|
||||
fontSize: 57.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.12,
|
||||
letterSpacing: -0.25,
|
||||
),
|
||||
displayMedium: TextStyle(
|
||||
fontSize: 45.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.16,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
displaySmall: TextStyle(
|
||||
fontSize: 36.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.22,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
headlineLarge: TextStyle(
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.25,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
headlineMedium: TextStyle(
|
||||
fontSize: 28.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.29,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
headlineSmall: TextStyle(
|
||||
fontSize: 24.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.33,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
titleLarge: TextStyle(
|
||||
fontSize: 22.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.27,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
titleMedium: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.5,
|
||||
letterSpacing: 0.15,
|
||||
),
|
||||
titleSmall: TextStyle(
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.43,
|
||||
letterSpacing: 0.1,
|
||||
),
|
||||
bodyLarge: TextStyle(
|
||||
fontSize: 16.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.5,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
bodyMedium: TextStyle(
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.43,
|
||||
letterSpacing: 0.25,
|
||||
),
|
||||
bodySmall: TextStyle(
|
||||
fontSize: 12.0,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.33,
|
||||
letterSpacing: 0.4,
|
||||
),
|
||||
labelLarge: TextStyle(
|
||||
fontSize: 14.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.43,
|
||||
letterSpacing: 0.1,
|
||||
),
|
||||
labelMedium: TextStyle(
|
||||
fontSize: 12.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.33,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
labelSmall: TextStyle(
|
||||
fontSize: 11.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.45,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
);
|
||||
|
||||
const textTheme = TextTheme(
|
||||
displayLarge: TextStyle(
|
||||
fontSize: 44, // 大标题保持较大尺寸
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.12,
|
||||
letterSpacing: -0.25,
|
||||
),
|
||||
displayMedium: TextStyle(
|
||||
fontSize: 36,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.16,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
displaySmall: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.22,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
headlineLarge: TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.25,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
headlineMedium: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.29,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
headlineSmall: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.33,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
titleLarge: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.27,
|
||||
letterSpacing: 0.0,
|
||||
),
|
||||
titleMedium: TextStyle(
|
||||
fontSize: 15, // 保持接近原始比例
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.5,
|
||||
letterSpacing: 0.15,
|
||||
),
|
||||
titleSmall: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.43,
|
||||
letterSpacing: 0.1,
|
||||
),
|
||||
bodyLarge: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.5,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
bodyMedium: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.43,
|
||||
letterSpacing: 0.25,
|
||||
),
|
||||
bodySmall: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1.33,
|
||||
letterSpacing: 0.4,
|
||||
),
|
||||
labelLarge: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.43,
|
||||
letterSpacing: 0.1,
|
||||
),
|
||||
labelMedium: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.33,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
labelSmall: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.45,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue