Update theme settings in app_settings_provider.dart

This commit is contained in:
Dr-Blank 2024-08-20 11:39:26 -04:00
parent 8d71020436
commit 74e0d77cf9
No known key found for this signature in database
GPG key ID: 7452CC63F210A266
10 changed files with 239 additions and 65 deletions

View file

@ -223,7 +223,7 @@ class _HeroSectionSubLabelWithIcon extends HookConsumerWidget {
final useFontAwesome =
icon.runtimeType == FontAwesomeIcons.book.runtimeType;
final useMaterialThemeOnItemPage =
ref.watch(appSettingsProvider).useMaterialThemeOnItemPage;
ref.watch(appSettingsProvider).themeSettings.useMaterialThemeOnItemPage;
final color = useMaterialThemeOnItemPage
? themeData.colorScheme.primary
: themeData.colorScheme.onSurface.withOpacity(0.75);
@ -356,7 +356,7 @@ class _BookCover extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final themeData = Theme.of(context);
final useMaterialThemeOnItemPage =
ref.watch(appSettingsProvider).useMaterialThemeOnItemPage;
ref.watch(appSettingsProvider).themeSettings.useMaterialThemeOnItemPage;
return ThemeSwitcher(
builder: (context) {

View file

@ -41,7 +41,7 @@ class LibraryItemPage extends HookConsumerWidget {
itemFromApi.valueOrNull?.media.metadata.asBookMetadataExpanded;
final useMaterialThemeOnItemPage =
ref.watch(appSettingsProvider).useMaterialThemeOnItemPage;
ref.watch(appSettingsProvider).themeSettings.useMaterialThemeOnItemPage;
AsyncValue<ColorScheme?> coverColorScheme = const AsyncValue.loading();
if (useMaterialThemeOnItemPage) {
coverColorScheme = ref.watch(

View file

@ -81,7 +81,7 @@ class MyApp extends ConsumerWidget {
// debugShowCheckedModeBanner: false,
theme: lightTheme,
darkTheme: darkTheme,
themeMode: ref.watch(appSettingsProvider).isDarkMode
themeMode: ref.watch(appSettingsProvider).themeSettings.isDarkMode
? ThemeMode.dark
: ThemeMode.light,
routerConfig: routerConfig,

View file

@ -44,7 +44,8 @@ class AppSettings extends _$AppSettings {
}
void toggleDarkMode() {
state = state.copyWith(isDarkMode: !state.isDarkMode);
state = state.copyWith
.themeSettings(isDarkMode: !state.themeSettings.isDarkMode);
}
void updateState(model.AppSettings newSettings) {

View file

@ -6,7 +6,7 @@ part of 'app_settings_provider.dart';
// RiverpodGenerator
// **************************************************************************
String _$appSettingsHash() => r'99bd35aff3c02252a4013c674fd885e841a7f703';
String _$appSettingsHash() => r'ab8fa4602242704a71b34dc2bb5dcb0c91092797';
/// See also [AppSettings].
@ProviderFor(AppSettings)

View file

@ -11,8 +11,7 @@ part 'app_settings.g.dart';
@freezed
class AppSettings with _$AppSettings {
const factory AppSettings({
@Default(true) bool isDarkMode,
@Default(true) bool useMaterialThemeOnItemPage,
@Default(ThemeSettings()) ThemeSettings themeSettings,
@Default(PlayerSettings()) PlayerSettings playerSettings,
@Default(DownloadSettings()) DownloadSettings downloadSettings,
}) = _AppSettings;
@ -21,6 +20,17 @@ class AppSettings with _$AppSettings {
_$AppSettingsFromJson(json);
}
@freezed
class ThemeSettings with _$ThemeSettings {
const factory ThemeSettings({
@Default(true) bool isDarkMode,
@Default(true) bool useMaterialThemeOnItemPage,
}) = _ThemeSettings;
factory ThemeSettings.fromJson(Map<String, dynamic> json) =>
_$ThemeSettingsFromJson(json);
}
@freezed
class PlayerSettings with _$PlayerSettings {
const factory PlayerSettings({

View file

@ -20,8 +20,7 @@ AppSettings _$AppSettingsFromJson(Map<String, dynamic> json) {
/// @nodoc
mixin _$AppSettings {
bool get isDarkMode => throw _privateConstructorUsedError;
bool get useMaterialThemeOnItemPage => throw _privateConstructorUsedError;
ThemeSettings get themeSettings => throw _privateConstructorUsedError;
PlayerSettings get playerSettings => throw _privateConstructorUsedError;
DownloadSettings get downloadSettings => throw _privateConstructorUsedError;
@ -38,11 +37,11 @@ abstract class $AppSettingsCopyWith<$Res> {
_$AppSettingsCopyWithImpl<$Res, AppSettings>;
@useResult
$Res call(
{bool isDarkMode,
bool useMaterialThemeOnItemPage,
{ThemeSettings themeSettings,
PlayerSettings playerSettings,
DownloadSettings downloadSettings});
$ThemeSettingsCopyWith<$Res> get themeSettings;
$PlayerSettingsCopyWith<$Res> get playerSettings;
$DownloadSettingsCopyWith<$Res> get downloadSettings;
}
@ -60,20 +59,15 @@ class _$AppSettingsCopyWithImpl<$Res, $Val extends AppSettings>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isDarkMode = null,
Object? useMaterialThemeOnItemPage = null,
Object? themeSettings = null,
Object? playerSettings = null,
Object? downloadSettings = null,
}) {
return _then(_value.copyWith(
isDarkMode: null == isDarkMode
? _value.isDarkMode
: isDarkMode // ignore: cast_nullable_to_non_nullable
as bool,
useMaterialThemeOnItemPage: null == useMaterialThemeOnItemPage
? _value.useMaterialThemeOnItemPage
: useMaterialThemeOnItemPage // ignore: cast_nullable_to_non_nullable
as bool,
themeSettings: null == themeSettings
? _value.themeSettings
: themeSettings // ignore: cast_nullable_to_non_nullable
as ThemeSettings,
playerSettings: null == playerSettings
? _value.playerSettings
: playerSettings // ignore: cast_nullable_to_non_nullable
@ -85,6 +79,14 @@ class _$AppSettingsCopyWithImpl<$Res, $Val extends AppSettings>
) as $Val);
}
@override
@pragma('vm:prefer-inline')
$ThemeSettingsCopyWith<$Res> get themeSettings {
return $ThemeSettingsCopyWith<$Res>(_value.themeSettings, (value) {
return _then(_value.copyWith(themeSettings: value) as $Val);
});
}
@override
@pragma('vm:prefer-inline')
$PlayerSettingsCopyWith<$Res> get playerSettings {
@ -111,11 +113,12 @@ abstract class _$$AppSettingsImplCopyWith<$Res>
@override
@useResult
$Res call(
{bool isDarkMode,
bool useMaterialThemeOnItemPage,
{ThemeSettings themeSettings,
PlayerSettings playerSettings,
DownloadSettings downloadSettings});
@override
$ThemeSettingsCopyWith<$Res> get themeSettings;
@override
$PlayerSettingsCopyWith<$Res> get playerSettings;
@override
@ -133,20 +136,15 @@ class __$$AppSettingsImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isDarkMode = null,
Object? useMaterialThemeOnItemPage = null,
Object? themeSettings = null,
Object? playerSettings = null,
Object? downloadSettings = null,
}) {
return _then(_$AppSettingsImpl(
isDarkMode: null == isDarkMode
? _value.isDarkMode
: isDarkMode // ignore: cast_nullable_to_non_nullable
as bool,
useMaterialThemeOnItemPage: null == useMaterialThemeOnItemPage
? _value.useMaterialThemeOnItemPage
: useMaterialThemeOnItemPage // ignore: cast_nullable_to_non_nullable
as bool,
themeSettings: null == themeSettings
? _value.themeSettings
: themeSettings // ignore: cast_nullable_to_non_nullable
as ThemeSettings,
playerSettings: null == playerSettings
? _value.playerSettings
: playerSettings // ignore: cast_nullable_to_non_nullable
@ -163,8 +161,7 @@ class __$$AppSettingsImplCopyWithImpl<$Res>
@JsonSerializable()
class _$AppSettingsImpl implements _AppSettings {
const _$AppSettingsImpl(
{this.isDarkMode = true,
this.useMaterialThemeOnItemPage = true,
{this.themeSettings = const ThemeSettings(),
this.playerSettings = const PlayerSettings(),
this.downloadSettings = const DownloadSettings()});
@ -173,10 +170,7 @@ class _$AppSettingsImpl implements _AppSettings {
@override
@JsonKey()
final bool isDarkMode;
@override
@JsonKey()
final bool useMaterialThemeOnItemPage;
final ThemeSettings themeSettings;
@override
@JsonKey()
final PlayerSettings playerSettings;
@ -186,7 +180,7 @@ class _$AppSettingsImpl implements _AppSettings {
@override
String toString() {
return 'AppSettings(isDarkMode: $isDarkMode, useMaterialThemeOnItemPage: $useMaterialThemeOnItemPage, playerSettings: $playerSettings, downloadSettings: $downloadSettings)';
return 'AppSettings(themeSettings: $themeSettings, playerSettings: $playerSettings, downloadSettings: $downloadSettings)';
}
@override
@ -194,12 +188,8 @@ class _$AppSettingsImpl implements _AppSettings {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$AppSettingsImpl &&
(identical(other.isDarkMode, isDarkMode) ||
other.isDarkMode == isDarkMode) &&
(identical(other.useMaterialThemeOnItemPage,
useMaterialThemeOnItemPage) ||
other.useMaterialThemeOnItemPage ==
useMaterialThemeOnItemPage) &&
(identical(other.themeSettings, themeSettings) ||
other.themeSettings == themeSettings) &&
(identical(other.playerSettings, playerSettings) ||
other.playerSettings == playerSettings) &&
(identical(other.downloadSettings, downloadSettings) ||
@ -208,8 +198,8 @@ class _$AppSettingsImpl implements _AppSettings {
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, isDarkMode,
useMaterialThemeOnItemPage, playerSettings, downloadSettings);
int get hashCode =>
Object.hash(runtimeType, themeSettings, playerSettings, downloadSettings);
@JsonKey(ignore: true)
@override
@ -227,8 +217,7 @@ class _$AppSettingsImpl implements _AppSettings {
abstract class _AppSettings implements AppSettings {
const factory _AppSettings(
{final bool isDarkMode,
final bool useMaterialThemeOnItemPage,
{final ThemeSettings themeSettings,
final PlayerSettings playerSettings,
final DownloadSettings downloadSettings}) = _$AppSettingsImpl;
@ -236,9 +225,7 @@ abstract class _AppSettings implements AppSettings {
_$AppSettingsImpl.fromJson;
@override
bool get isDarkMode;
@override
bool get useMaterialThemeOnItemPage;
ThemeSettings get themeSettings;
@override
PlayerSettings get playerSettings;
@override
@ -249,6 +236,168 @@ abstract class _AppSettings implements AppSettings {
throw _privateConstructorUsedError;
}
ThemeSettings _$ThemeSettingsFromJson(Map<String, dynamic> json) {
return _ThemeSettings.fromJson(json);
}
/// @nodoc
mixin _$ThemeSettings {
bool get isDarkMode => throw _privateConstructorUsedError;
bool get useMaterialThemeOnItemPage => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ThemeSettingsCopyWith<ThemeSettings> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ThemeSettingsCopyWith<$Res> {
factory $ThemeSettingsCopyWith(
ThemeSettings value, $Res Function(ThemeSettings) then) =
_$ThemeSettingsCopyWithImpl<$Res, ThemeSettings>;
@useResult
$Res call({bool isDarkMode, bool useMaterialThemeOnItemPage});
}
/// @nodoc
class _$ThemeSettingsCopyWithImpl<$Res, $Val extends ThemeSettings>
implements $ThemeSettingsCopyWith<$Res> {
_$ThemeSettingsCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isDarkMode = null,
Object? useMaterialThemeOnItemPage = null,
}) {
return _then(_value.copyWith(
isDarkMode: null == isDarkMode
? _value.isDarkMode
: isDarkMode // ignore: cast_nullable_to_non_nullable
as bool,
useMaterialThemeOnItemPage: null == useMaterialThemeOnItemPage
? _value.useMaterialThemeOnItemPage
: useMaterialThemeOnItemPage // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
/// @nodoc
abstract class _$$ThemeSettingsImplCopyWith<$Res>
implements $ThemeSettingsCopyWith<$Res> {
factory _$$ThemeSettingsImplCopyWith(
_$ThemeSettingsImpl value, $Res Function(_$ThemeSettingsImpl) then) =
__$$ThemeSettingsImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({bool isDarkMode, bool useMaterialThemeOnItemPage});
}
/// @nodoc
class __$$ThemeSettingsImplCopyWithImpl<$Res>
extends _$ThemeSettingsCopyWithImpl<$Res, _$ThemeSettingsImpl>
implements _$$ThemeSettingsImplCopyWith<$Res> {
__$$ThemeSettingsImplCopyWithImpl(
_$ThemeSettingsImpl _value, $Res Function(_$ThemeSettingsImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isDarkMode = null,
Object? useMaterialThemeOnItemPage = null,
}) {
return _then(_$ThemeSettingsImpl(
isDarkMode: null == isDarkMode
? _value.isDarkMode
: isDarkMode // ignore: cast_nullable_to_non_nullable
as bool,
useMaterialThemeOnItemPage: null == useMaterialThemeOnItemPage
? _value.useMaterialThemeOnItemPage
: useMaterialThemeOnItemPage // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
/// @nodoc
@JsonSerializable()
class _$ThemeSettingsImpl implements _ThemeSettings {
const _$ThemeSettingsImpl(
{this.isDarkMode = true, this.useMaterialThemeOnItemPage = true});
factory _$ThemeSettingsImpl.fromJson(Map<String, dynamic> json) =>
_$$ThemeSettingsImplFromJson(json);
@override
@JsonKey()
final bool isDarkMode;
@override
@JsonKey()
final bool useMaterialThemeOnItemPage;
@override
String toString() {
return 'ThemeSettings(isDarkMode: $isDarkMode, useMaterialThemeOnItemPage: $useMaterialThemeOnItemPage)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ThemeSettingsImpl &&
(identical(other.isDarkMode, isDarkMode) ||
other.isDarkMode == isDarkMode) &&
(identical(other.useMaterialThemeOnItemPage,
useMaterialThemeOnItemPage) ||
other.useMaterialThemeOnItemPage ==
useMaterialThemeOnItemPage));
}
@JsonKey(ignore: true)
@override
int get hashCode =>
Object.hash(runtimeType, isDarkMode, useMaterialThemeOnItemPage);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$ThemeSettingsImplCopyWith<_$ThemeSettingsImpl> get copyWith =>
__$$ThemeSettingsImplCopyWithImpl<_$ThemeSettingsImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$ThemeSettingsImplToJson(
this,
);
}
}
abstract class _ThemeSettings implements ThemeSettings {
const factory _ThemeSettings(
{final bool isDarkMode,
final bool useMaterialThemeOnItemPage}) = _$ThemeSettingsImpl;
factory _ThemeSettings.fromJson(Map<String, dynamic> json) =
_$ThemeSettingsImpl.fromJson;
@override
bool get isDarkMode;
@override
bool get useMaterialThemeOnItemPage;
@override
@JsonKey(ignore: true)
_$$ThemeSettingsImplCopyWith<_$ThemeSettingsImpl> get copyWith =>
throw _privateConstructorUsedError;
}
PlayerSettings _$PlayerSettingsFromJson(Map<String, dynamic> json) {
return _PlayerSettings.fromJson(json);
}

View file

@ -8,9 +8,10 @@ part of 'app_settings.dart';
_$AppSettingsImpl _$$AppSettingsImplFromJson(Map<String, dynamic> json) =>
_$AppSettingsImpl(
isDarkMode: json['isDarkMode'] as bool? ?? true,
useMaterialThemeOnItemPage:
json['useMaterialThemeOnItemPage'] as bool? ?? true,
themeSettings: json['themeSettings'] == null
? const ThemeSettings()
: ThemeSettings.fromJson(
json['themeSettings'] as Map<String, dynamic>),
playerSettings: json['playerSettings'] == null
? const PlayerSettings()
: PlayerSettings.fromJson(
@ -23,12 +24,24 @@ _$AppSettingsImpl _$$AppSettingsImplFromJson(Map<String, dynamic> json) =>
Map<String, dynamic> _$$AppSettingsImplToJson(_$AppSettingsImpl instance) =>
<String, dynamic>{
'isDarkMode': instance.isDarkMode,
'useMaterialThemeOnItemPage': instance.useMaterialThemeOnItemPage,
'themeSettings': instance.themeSettings,
'playerSettings': instance.playerSettings,
'downloadSettings': instance.downloadSettings,
};
_$ThemeSettingsImpl _$$ThemeSettingsImplFromJson(Map<String, dynamic> json) =>
_$ThemeSettingsImpl(
isDarkMode: json['isDarkMode'] as bool? ?? true,
useMaterialThemeOnItemPage:
json['useMaterialThemeOnItemPage'] as bool? ?? true,
);
Map<String, dynamic> _$$ThemeSettingsImplToJson(_$ThemeSettingsImpl instance) =>
<String, dynamic>{
'isDarkMode': instance.isDarkMode,
'useMaterialThemeOnItemPage': instance.useMaterialThemeOnItemPage,
};
_$PlayerSettingsImpl _$$PlayerSettingsImplFromJson(Map<String, dynamic> json) =>
_$PlayerSettingsImpl(
miniPlayerSettings: json['miniPlayerSettings'] == null

View file

@ -44,10 +44,10 @@ class AppSettingsPage extends HookConsumerWidget {
),
tiles: [
SettingsTile.switchTile(
initialValue: appSettings.isDarkMode,
initialValue: appSettings.themeSettings.isDarkMode,
title: const Text('Dark Mode'),
description: const Text('we all know dark mode is better'),
leading: appSettings.isDarkMode
leading: appSettings.themeSettings.isDarkMode
? const Icon(Icons.dark_mode)
: const Icon(Icons.light_mode),
onToggle: (value) {
@ -55,17 +55,18 @@ class AppSettingsPage extends HookConsumerWidget {
},
),
SettingsTile.switchTile(
initialValue: appSettings.useMaterialThemeOnItemPage,
initialValue:
appSettings.themeSettings.useMaterialThemeOnItemPage,
title: const Text('Adaptive Theme on Item Page'),
description: const Text(
'get fancy with the colors on the item page at the cost of some performance',
),
leading: appSettings.useMaterialThemeOnItemPage
leading: appSettings.themeSettings.useMaterialThemeOnItemPage
? const Icon(Icons.auto_fix_high)
: const Icon(Icons.auto_fix_off),
onToggle: (value) {
ref.read(appSettingsProvider.notifier).updateState(
appSettings.copyWith(
appSettings.copyWith.themeSettings(
useMaterialThemeOnItemPage: value,
),
);

View file

@ -224,7 +224,7 @@ class _BookOnShelfPlayButton extends HookConsumerWidget {
var strokeWidth = size / 8;
final useMaterialThemeOnItemPage =
ref.watch(appSettingsProvider).useMaterialThemeOnItemPage;
ref.watch(appSettingsProvider).themeSettings.useMaterialThemeOnItemPage;
AsyncValue<ColorScheme?> coverColorScheme = const AsyncValue.loading();
if (useMaterialThemeOnItemPage && isCurrentBookSetInPlayer) {