feat: multiple theming options (#50)

* refactor: consolidate theme definitions by removing separate dark and light theme files

* feat: integrate dynamic color support and enhance theme settings management

* feat: add theme settings route and update theme management in app settings

* feat: enhance theme management by integrating high contrast support in various components

* feat: implement mode selection dialog for theme settings and enhance button functionality

* refactor: update theme import paths and consolidate theme provider files

* feat: enhance theme management by integrating theme selection based on audiobook playback

* refactor: update default value for useMaterialThemeFromSystem to false in theme settings

* refactor: adjust high contrast condition order in theme settings for consistency

* refactor: rename useMaterialThemeOfPlayingItem to useCurrentPlayerThemeThroughoutApp for clarity

* refactor: correct spelling in system theme provider and replace with updated implementation

* refactor: extract restore backup dialog into a separate widget for improved readability

* refactor: reorganize settings sections for clarity and improve restore dialog functionality
This commit is contained in:
Dr.Blank 2024-10-05 10:01:08 -04:00 committed by GitHub
parent 758e4cdc83
commit ff83c2cc63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 935 additions and 194 deletions

View file

@ -12,6 +12,7 @@
"audioplayers", "audioplayers",
"autolabeler", "autolabeler",
"Autovalidate", "Autovalidate",
"Checkmark",
"deeplinking", "deeplinking",
"fullscreen", "fullscreen",
"Lerp", "Lerp",

View file

@ -15,7 +15,7 @@ import 'package:vaani/settings/app_settings_provider.dart';
import 'package:vaani/shared/extensions/duration_format.dart'; import 'package:vaani/shared/extensions/duration_format.dart';
import 'package:vaani/shared/extensions/model_conversions.dart'; import 'package:vaani/shared/extensions/model_conversions.dart';
import 'package:vaani/shared/widgets/shelves/book_shelf.dart'; import 'package:vaani/shared/widgets/shelves/book_shelf.dart';
import 'package:vaani/theme/theme_from_cover_provider.dart'; import 'package:vaani/theme/providers/theme_from_cover_provider.dart';
class LibraryItemHeroSection extends HookConsumerWidget { class LibraryItemHeroSection extends HookConsumerWidget {
const LibraryItemHeroSection({ const LibraryItemHeroSection({
@ -353,16 +353,17 @@ class _BookCover extends HookConsumerWidget {
final coverImage = ref.watch(coverImageProvider(itemId)); final coverImage = ref.watch(coverImageProvider(itemId));
final themeData = Theme.of(context); final themeData = Theme.of(context);
// final item = ref.watch(libraryItemProvider(itemId)); // final item = ref.watch(libraryItemProvider(itemId));
final useMaterialThemeOnItemPage = final themeSettings = ref.watch(appSettingsProvider).themeSettings;
ref.watch(appSettingsProvider).themeSettings.useMaterialThemeOnItemPage;
ColorScheme? coverColorScheme; ColorScheme? coverColorScheme;
if (useMaterialThemeOnItemPage) { if (themeSettings.useMaterialThemeOnItemPage) {
coverColorScheme = ref coverColorScheme = ref
.watch( .watch(
themeOfLibraryItemProvider( themeOfLibraryItemProvider(
itemId, itemId,
brightness: Theme.of(context).brightness, brightness: Theme.of(context).brightness,
highContrast: themeSettings.highContrast ||
MediaQuery.of(context).highContrast,
), ),
) )
.valueOrNull; .valueOrNull;
@ -371,7 +372,7 @@ class _BookCover extends HookConsumerWidget {
return ThemeSwitcher( return ThemeSwitcher(
builder: (context) { builder: (context) {
// change theme after 2 seconds // change theme after 2 seconds
if (useMaterialThemeOnItemPage) { if (themeSettings.useMaterialThemeOnItemPage) {
Future.delayed(150.ms, () { Future.delayed(150.ms, () {
try { try {
ThemeSwitcher.of(context).changeTheme( ThemeSwitcher.of(context).changeTheme(

View file

@ -14,7 +14,7 @@ import 'package:vaani/features/player/providers/player_form.dart';
import 'package:vaani/settings/app_settings_provider.dart'; import 'package:vaani/settings/app_settings_provider.dart';
import 'package:vaani/shared/extensions/inverse_lerp.dart'; import 'package:vaani/shared/extensions/inverse_lerp.dart';
import 'package:vaani/shared/widgets/shelves/book_shelf.dart'; import 'package:vaani/shared/widgets/shelves/book_shelf.dart';
import 'package:vaani/theme/theme_from_cover_provider.dart'; import 'package:vaani/theme/providers/theme_from_cover_provider.dart';
import 'player_when_expanded.dart'; import 'player_when_expanded.dart';
import 'player_when_minimized.dart'; import 'player_when_minimized.dart';
@ -65,6 +65,8 @@ class AudiobookPlayer extends HookConsumerWidget {
themeOfLibraryItemProvider( themeOfLibraryItemProvider(
itemBeingPlayed.valueOrNull?.id, itemBeingPlayed.valueOrNull?.id,
brightness: Theme.of(context).brightness, brightness: Theme.of(context).brightness,
highContrast: appSettings.themeSettings.highContrast ||
MediaQuery.of(context).highContrast,
), ),
); );

View file

@ -1,3 +1,4 @@
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
@ -7,12 +8,15 @@ import 'package:vaani/features/downloads/providers/download_manager.dart';
import 'package:vaani/features/logging/core/logger.dart'; import 'package:vaani/features/logging/core/logger.dart';
import 'package:vaani/features/playback_reporting/providers/playback_reporter_provider.dart'; import 'package:vaani/features/playback_reporting/providers/playback_reporter_provider.dart';
import 'package:vaani/features/player/core/init.dart'; import 'package:vaani/features/player/core/init.dart';
import 'package:vaani/features/player/providers/audiobook_player.dart'; import 'package:vaani/features/player/providers/audiobook_player.dart'
show audiobookPlayerProvider, simpleAudiobookPlayerProvider;
import 'package:vaani/features/shake_detection/providers/shake_detector.dart'; import 'package:vaani/features/shake_detection/providers/shake_detector.dart';
import 'package:vaani/features/sleep_timer/providers/sleep_timer_provider.dart'; import 'package:vaani/features/sleep_timer/providers/sleep_timer_provider.dart';
import 'package:vaani/router/router.dart'; import 'package:vaani/router/router.dart';
import 'package:vaani/settings/api_settings_provider.dart'; import 'package:vaani/settings/api_settings_provider.dart';
import 'package:vaani/settings/app_settings_provider.dart'; import 'package:vaani/settings/app_settings_provider.dart';
import 'package:vaani/theme/providers/system_theme_provider.dart';
import 'package:vaani/theme/providers/theme_from_cover_provider.dart';
import 'package:vaani/theme/theme.dart'; import 'package:vaani/theme/theme.dart';
final appLogger = Logger('vaani'); final appLogger = Logger('vaani');
@ -51,16 +55,77 @@ class MyApp extends ConsumerWidget {
if (needOnboarding) { if (needOnboarding) {
routerConfig.goNamed(Routes.onboarding.name); routerConfig.goNamed(Routes.onboarding.name);
} }
final appSettings = ref.watch(appSettingsProvider);
final themeSettings = appSettings.themeSettings;
ColorScheme lightColorScheme = brandLightColorScheme;
ColorScheme darkColorScheme = brandDarkColorScheme;
final shouldUseHighContrast =
themeSettings.highContrast || MediaQuery.of(context).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) {
final player = ref.watch(audiobookPlayerProvider);
if (player.book != null) {
final themeLight = ref.watch(
themeOfLibraryItemProvider(
player.book!.libraryItemId,
highContrast: shouldUseHighContrast,
brightness: Brightness.light,
),
);
final themeDark = ref.watch(
themeOfLibraryItemProvider(
player.book!.libraryItemId,
highContrast: shouldUseHighContrast,
brightness: Brightness.dark,
),
);
if (themeLight.valueOrNull != null && themeDark.valueOrNull != null) {
lightColorScheme = themeLight.valueOrNull!;
darkColorScheme = themeDark.valueOrNull!;
}
}
}
final appThemeLight = ThemeData(
useMaterial3: true,
colorScheme: lightColorScheme.harmonized(),
);
final appThemeDark = ThemeData(
useMaterial3: true,
colorScheme: darkColorScheme.harmonized(),
brightness: Brightness.dark,
// TODO bottom sheet theme is not working
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: darkColorScheme.surface,
),
);
try { try {
return MaterialApp.router( return MaterialApp.router(
// debugShowCheckedModeBanner: false, // debugShowCheckedModeBanner: false,
theme: lightTheme, theme: appThemeLight,
darkTheme: darkTheme, darkTheme: appThemeDark,
themeMode: ref.watch(appSettingsProvider).themeSettings.isDarkMode themeMode: themeSettings.themeMode,
? ThemeMode.dark
: ThemeMode.light,
routerConfig: routerConfig, routerConfig: routerConfig,
themeAnimationCurve: Curves.easeInOut,
); );
} catch (e) { } catch (e) {
debugPrintStack(stackTrace: StackTrace.current, label: e.toString()); debugPrintStack(stackTrace: StackTrace.current, label: e.toString());

View file

@ -27,6 +27,11 @@ class Routes {
pathName: 'config', pathName: 'config',
name: 'settings', name: 'settings',
); );
static const themeSettings = _SimpleRoute(
pathName: 'theme',
name: 'themeSettings',
parentRoute: settings,
);
static const autoSleepTimerSettings = _SimpleRoute( static const autoSleepTimerSettings = _SimpleRoute(
pathName: 'autoSleepTimer', pathName: 'autoSleepTimer',
name: 'autoSleepTimerSettings', name: 'autoSleepTimerSettings',

View file

@ -17,6 +17,7 @@ import 'package:vaani/settings/view/auto_sleep_timer_settings_page.dart';
import 'package:vaani/settings/view/notification_settings_page.dart'; import 'package:vaani/settings/view/notification_settings_page.dart';
import 'package:vaani/settings/view/player_settings_page.dart'; import 'package:vaani/settings/view/player_settings_page.dart';
import 'package:vaani/settings/view/shake_detector_settings_page.dart'; import 'package:vaani/settings/view/shake_detector_settings_page.dart';
import 'package:vaani/settings/view/theme_settings_page.dart';
import 'scaffold_with_nav_bar.dart'; import 'scaffold_with_nav_bar.dart';
import 'transitions/slide.dart'; import 'transitions/slide.dart';
@ -178,6 +179,13 @@ class MyAppRouter {
// builder: (context, state) => const AppSettingsPage(), // builder: (context, state) => const AppSettingsPage(),
pageBuilder: defaultPageBuilder(const AppSettingsPage()), pageBuilder: defaultPageBuilder(const AppSettingsPage()),
routes: [ routes: [
GoRoute(
path: Routes.themeSettings.pathName,
name: Routes.themeSettings.name,
pageBuilder: defaultPageBuilder(
const ThemeSettingsPage(),
),
),
GoRoute( GoRoute(
path: Routes.autoSleepTimerSettings.pathName, path: Routes.autoSleepTimerSettings.pathName,
name: Routes.autoSleepTimerSettings.name, name: Routes.autoSleepTimerSettings.name,

View file

@ -47,11 +47,6 @@ class AppSettings extends _$AppSettings {
_logger.fine('wrote settings to box: $state'); _logger.fine('wrote settings to box: $state');
} }
void toggleDarkMode() {
state = state.copyWith
.themeSettings(isDarkMode: !state.themeSettings.isDarkMode);
}
void update(model.AppSettings newSettings) { void update(model.AppSettings newSettings) {
state = newSettings; state = newSettings;
} }

View file

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

View file

@ -28,7 +28,10 @@ class AppSettings with _$AppSettings {
@freezed @freezed
class ThemeSettings with _$ThemeSettings { class ThemeSettings with _$ThemeSettings {
const factory ThemeSettings({ const factory ThemeSettings({
@Default(true) bool isDarkMode, @Default(ThemeMode.system) ThemeMode themeMode,
@Default(false) bool highContrast,
@Default(false) bool useMaterialThemeFromSystem,
@Default('#FF311B92') String customThemeColor,
@Default(true) bool useMaterialThemeOnItemPage, @Default(true) bool useMaterialThemeOnItemPage,
@Default(true) bool useCurrentPlayerThemeThroughoutApp, @Default(true) bool useCurrentPlayerThemeThroughoutApp,
}) = _ThemeSettings; }) = _ThemeSettings;

View file

@ -378,7 +378,10 @@ ThemeSettings _$ThemeSettingsFromJson(Map<String, dynamic> json) {
/// @nodoc /// @nodoc
mixin _$ThemeSettings { mixin _$ThemeSettings {
bool get isDarkMode => throw _privateConstructorUsedError; ThemeMode get themeMode => throw _privateConstructorUsedError;
bool get highContrast => throw _privateConstructorUsedError;
bool get useMaterialThemeFromSystem => throw _privateConstructorUsedError;
String get customThemeColor => throw _privateConstructorUsedError;
bool get useMaterialThemeOnItemPage => throw _privateConstructorUsedError; bool get useMaterialThemeOnItemPage => throw _privateConstructorUsedError;
bool get useCurrentPlayerThemeThroughoutApp => bool get useCurrentPlayerThemeThroughoutApp =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@ -400,7 +403,10 @@ abstract class $ThemeSettingsCopyWith<$Res> {
_$ThemeSettingsCopyWithImpl<$Res, ThemeSettings>; _$ThemeSettingsCopyWithImpl<$Res, ThemeSettings>;
@useResult @useResult
$Res call( $Res call(
{bool isDarkMode, {ThemeMode themeMode,
bool highContrast,
bool useMaterialThemeFromSystem,
String customThemeColor,
bool useMaterialThemeOnItemPage, bool useMaterialThemeOnItemPage,
bool useCurrentPlayerThemeThroughoutApp}); bool useCurrentPlayerThemeThroughoutApp});
} }
@ -420,15 +426,30 @@ class _$ThemeSettingsCopyWithImpl<$Res, $Val extends ThemeSettings>
@pragma('vm:prefer-inline') @pragma('vm:prefer-inline')
@override @override
$Res call({ $Res call({
Object? isDarkMode = null, Object? themeMode = null,
Object? highContrast = null,
Object? useMaterialThemeFromSystem = null,
Object? customThemeColor = null,
Object? useMaterialThemeOnItemPage = null, Object? useMaterialThemeOnItemPage = null,
Object? useCurrentPlayerThemeThroughoutApp = null, Object? useCurrentPlayerThemeThroughoutApp = null,
}) { }) {
return _then(_value.copyWith( return _then(_value.copyWith(
isDarkMode: null == isDarkMode themeMode: null == themeMode
? _value.isDarkMode ? _value.themeMode
: isDarkMode // ignore: cast_nullable_to_non_nullable : themeMode // ignore: cast_nullable_to_non_nullable
as ThemeMode,
highContrast: null == highContrast
? _value.highContrast
: highContrast // ignore: cast_nullable_to_non_nullable
as bool, as bool,
useMaterialThemeFromSystem: null == useMaterialThemeFromSystem
? _value.useMaterialThemeFromSystem
: useMaterialThemeFromSystem // ignore: cast_nullable_to_non_nullable
as bool,
customThemeColor: null == customThemeColor
? _value.customThemeColor
: customThemeColor // ignore: cast_nullable_to_non_nullable
as String,
useMaterialThemeOnItemPage: null == useMaterialThemeOnItemPage useMaterialThemeOnItemPage: null == useMaterialThemeOnItemPage
? _value.useMaterialThemeOnItemPage ? _value.useMaterialThemeOnItemPage
: useMaterialThemeOnItemPage // ignore: cast_nullable_to_non_nullable : useMaterialThemeOnItemPage // ignore: cast_nullable_to_non_nullable
@ -451,7 +472,10 @@ abstract class _$$ThemeSettingsImplCopyWith<$Res>
@override @override
@useResult @useResult
$Res call( $Res call(
{bool isDarkMode, {ThemeMode themeMode,
bool highContrast,
bool useMaterialThemeFromSystem,
String customThemeColor,
bool useMaterialThemeOnItemPage, bool useMaterialThemeOnItemPage,
bool useCurrentPlayerThemeThroughoutApp}); bool useCurrentPlayerThemeThroughoutApp});
} }
@ -469,15 +493,30 @@ class __$$ThemeSettingsImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline') @pragma('vm:prefer-inline')
@override @override
$Res call({ $Res call({
Object? isDarkMode = null, Object? themeMode = null,
Object? highContrast = null,
Object? useMaterialThemeFromSystem = null,
Object? customThemeColor = null,
Object? useMaterialThemeOnItemPage = null, Object? useMaterialThemeOnItemPage = null,
Object? useCurrentPlayerThemeThroughoutApp = null, Object? useCurrentPlayerThemeThroughoutApp = null,
}) { }) {
return _then(_$ThemeSettingsImpl( return _then(_$ThemeSettingsImpl(
isDarkMode: null == isDarkMode themeMode: null == themeMode
? _value.isDarkMode ? _value.themeMode
: isDarkMode // ignore: cast_nullable_to_non_nullable : themeMode // ignore: cast_nullable_to_non_nullable
as ThemeMode,
highContrast: null == highContrast
? _value.highContrast
: highContrast // ignore: cast_nullable_to_non_nullable
as bool, as bool,
useMaterialThemeFromSystem: null == useMaterialThemeFromSystem
? _value.useMaterialThemeFromSystem
: useMaterialThemeFromSystem // ignore: cast_nullable_to_non_nullable
as bool,
customThemeColor: null == customThemeColor
? _value.customThemeColor
: customThemeColor // ignore: cast_nullable_to_non_nullable
as String,
useMaterialThemeOnItemPage: null == useMaterialThemeOnItemPage useMaterialThemeOnItemPage: null == useMaterialThemeOnItemPage
? _value.useMaterialThemeOnItemPage ? _value.useMaterialThemeOnItemPage
: useMaterialThemeOnItemPage // ignore: cast_nullable_to_non_nullable : useMaterialThemeOnItemPage // ignore: cast_nullable_to_non_nullable
@ -495,7 +534,10 @@ class __$$ThemeSettingsImplCopyWithImpl<$Res>
@JsonSerializable() @JsonSerializable()
class _$ThemeSettingsImpl implements _ThemeSettings { class _$ThemeSettingsImpl implements _ThemeSettings {
const _$ThemeSettingsImpl( const _$ThemeSettingsImpl(
{this.isDarkMode = true, {this.themeMode = ThemeMode.system,
this.highContrast = false,
this.useMaterialThemeFromSystem = false,
this.customThemeColor = '#FF311B92',
this.useMaterialThemeOnItemPage = true, this.useMaterialThemeOnItemPage = true,
this.useCurrentPlayerThemeThroughoutApp = true}); this.useCurrentPlayerThemeThroughoutApp = true});
@ -504,7 +546,16 @@ class _$ThemeSettingsImpl implements _ThemeSettings {
@override @override
@JsonKey() @JsonKey()
final bool isDarkMode; final ThemeMode themeMode;
@override
@JsonKey()
final bool highContrast;
@override
@JsonKey()
final bool useMaterialThemeFromSystem;
@override
@JsonKey()
final String customThemeColor;
@override @override
@JsonKey() @JsonKey()
final bool useMaterialThemeOnItemPage; final bool useMaterialThemeOnItemPage;
@ -514,7 +565,7 @@ class _$ThemeSettingsImpl implements _ThemeSettings {
@override @override
String toString() { String toString() {
return 'ThemeSettings(isDarkMode: $isDarkMode, useMaterialThemeOnItemPage: $useMaterialThemeOnItemPage, useCurrentPlayerThemeThroughoutApp: $useCurrentPlayerThemeThroughoutApp)'; return 'ThemeSettings(themeMode: $themeMode, highContrast: $highContrast, useMaterialThemeFromSystem: $useMaterialThemeFromSystem, customThemeColor: $customThemeColor, useMaterialThemeOnItemPage: $useMaterialThemeOnItemPage, useCurrentPlayerThemeThroughoutApp: $useCurrentPlayerThemeThroughoutApp)';
} }
@override @override
@ -522,8 +573,16 @@ class _$ThemeSettingsImpl implements _ThemeSettings {
return identical(this, other) || return identical(this, other) ||
(other.runtimeType == runtimeType && (other.runtimeType == runtimeType &&
other is _$ThemeSettingsImpl && other is _$ThemeSettingsImpl &&
(identical(other.isDarkMode, isDarkMode) || (identical(other.themeMode, themeMode) ||
other.isDarkMode == isDarkMode) && other.themeMode == themeMode) &&
(identical(other.highContrast, highContrast) ||
other.highContrast == highContrast) &&
(identical(other.useMaterialThemeFromSystem,
useMaterialThemeFromSystem) ||
other.useMaterialThemeFromSystem ==
useMaterialThemeFromSystem) &&
(identical(other.customThemeColor, customThemeColor) ||
other.customThemeColor == customThemeColor) &&
(identical(other.useMaterialThemeOnItemPage, (identical(other.useMaterialThemeOnItemPage,
useMaterialThemeOnItemPage) || useMaterialThemeOnItemPage) ||
other.useMaterialThemeOnItemPage == other.useMaterialThemeOnItemPage ==
@ -536,8 +595,14 @@ class _$ThemeSettingsImpl implements _ThemeSettings {
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@override @override
int get hashCode => Object.hash(runtimeType, isDarkMode, int get hashCode => Object.hash(
useMaterialThemeOnItemPage, useCurrentPlayerThemeThroughoutApp); runtimeType,
themeMode,
highContrast,
useMaterialThemeFromSystem,
customThemeColor,
useMaterialThemeOnItemPage,
useCurrentPlayerThemeThroughoutApp);
/// Create a copy of ThemeSettings /// Create a copy of ThemeSettings
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@ -557,7 +622,10 @@ class _$ThemeSettingsImpl implements _ThemeSettings {
abstract class _ThemeSettings implements ThemeSettings { abstract class _ThemeSettings implements ThemeSettings {
const factory _ThemeSettings( const factory _ThemeSettings(
{final bool isDarkMode, {final ThemeMode themeMode,
final bool highContrast,
final bool useMaterialThemeFromSystem,
final String customThemeColor,
final bool useMaterialThemeOnItemPage, final bool useMaterialThemeOnItemPage,
final bool useCurrentPlayerThemeThroughoutApp}) = _$ThemeSettingsImpl; final bool useCurrentPlayerThemeThroughoutApp}) = _$ThemeSettingsImpl;
@ -565,7 +633,13 @@ abstract class _ThemeSettings implements ThemeSettings {
_$ThemeSettingsImpl.fromJson; _$ThemeSettingsImpl.fromJson;
@override @override
bool get isDarkMode; ThemeMode get themeMode;
@override
bool get highContrast;
@override
bool get useMaterialThemeFromSystem;
@override
String get customThemeColor;
@override @override
bool get useMaterialThemeOnItemPage; bool get useMaterialThemeOnItemPage;
@override @override

View file

@ -46,7 +46,12 @@ Map<String, dynamic> _$$AppSettingsImplToJson(_$AppSettingsImpl instance) =>
_$ThemeSettingsImpl _$$ThemeSettingsImplFromJson(Map<String, dynamic> json) => _$ThemeSettingsImpl _$$ThemeSettingsImplFromJson(Map<String, dynamic> json) =>
_$ThemeSettingsImpl( _$ThemeSettingsImpl(
isDarkMode: json['isDarkMode'] as bool? ?? true, themeMode: $enumDecodeNullable(_$ThemeModeEnumMap, json['themeMode']) ??
ThemeMode.system,
highContrast: json['highContrast'] as bool? ?? false,
useMaterialThemeFromSystem:
json['useMaterialThemeFromSystem'] as bool? ?? false,
customThemeColor: json['customThemeColor'] as String? ?? '#FF311B92',
useMaterialThemeOnItemPage: useMaterialThemeOnItemPage:
json['useMaterialThemeOnItemPage'] as bool? ?? true, json['useMaterialThemeOnItemPage'] as bool? ?? true,
useCurrentPlayerThemeThroughoutApp: useCurrentPlayerThemeThroughoutApp:
@ -55,12 +60,21 @@ _$ThemeSettingsImpl _$$ThemeSettingsImplFromJson(Map<String, dynamic> json) =>
Map<String, dynamic> _$$ThemeSettingsImplToJson(_$ThemeSettingsImpl instance) => Map<String, dynamic> _$$ThemeSettingsImplToJson(_$ThemeSettingsImpl instance) =>
<String, dynamic>{ <String, dynamic>{
'isDarkMode': instance.isDarkMode, 'themeMode': _$ThemeModeEnumMap[instance.themeMode]!,
'highContrast': instance.highContrast,
'useMaterialThemeFromSystem': instance.useMaterialThemeFromSystem,
'customThemeColor': instance.customThemeColor,
'useMaterialThemeOnItemPage': instance.useMaterialThemeOnItemPage, 'useMaterialThemeOnItemPage': instance.useMaterialThemeOnItemPage,
'useCurrentPlayerThemeThroughoutApp': 'useCurrentPlayerThemeThroughoutApp':
instance.useCurrentPlayerThemeThroughoutApp, instance.useCurrentPlayerThemeThroughoutApp,
}; };
const _$ThemeModeEnumMap = {
ThemeMode.system: 'system',
ThemeMode.light: 'light',
ThemeMode.dark: 'dark',
};
_$PlayerSettingsImpl _$$PlayerSettingsImplFromJson(Map<String, dynamic> json) => _$PlayerSettingsImpl _$$PlayerSettingsImplFromJson(Map<String, dynamic> json) =>
_$PlayerSettingsImpl( _$PlayerSettingsImpl(
miniPlayerSettings: json['miniPlayerSettings'] == null miniPlayerSettings: json['miniPlayerSettings'] == null

View file

@ -7,11 +7,10 @@ import 'package:flutter_settings_ui/flutter_settings_ui.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:material_symbols_icons/symbols.dart'; import 'package:material_symbols_icons/symbols.dart';
import 'package:vaani/api/authenticated_user_provider.dart';
import 'package:vaani/api/server_provider.dart';
import 'package:vaani/router/router.dart'; import 'package:vaani/router/router.dart';
import 'package:vaani/settings/app_settings_provider.dart'; import 'package:vaani/settings/app_settings_provider.dart';
import 'package:vaani/settings/models/app_settings.dart' as model; import 'package:vaani/settings/models/app_settings.dart' as model;
import 'package:vaani/settings/view/buttons.dart';
import 'package:vaani/settings/view/simple_settings_page.dart'; import 'package:vaani/settings/view/simple_settings_page.dart';
import 'package:vaani/settings/view/widgets/navigation_with_switch_tile.dart'; import 'package:vaani/settings/view/widgets/navigation_with_switch_tile.dart';
@ -23,58 +22,11 @@ class AppSettingsPage extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final appSettings = ref.watch(appSettingsProvider); final appSettings = ref.watch(appSettingsProvider);
final registeredServers = ref.watch(audiobookShelfServerProvider);
final registeredServersAsList = registeredServers.toList();
final availableUsers = ref.watch(authenticatedUserProvider);
final serverURIController = useTextEditingController();
final sleepTimerSettings = appSettings.sleepTimerSettings; final sleepTimerSettings = appSettings.sleepTimerSettings;
return SimpleSettingsPage( return SimpleSettingsPage(
title: const Text('App Settings'), title: const Text('App Settings'),
sections: [ sections: [
// Appearance section
SettingsSection(
margin: const EdgeInsetsDirectional.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
title: Text(
'Appearance',
style: Theme.of(context).textTheme.titleLarge,
),
tiles: [
SettingsTile.switchTile(
initialValue: appSettings.themeSettings.isDarkMode,
title: const Text('Dark Mode'),
description: const Text('we all know dark mode is better'),
leading: appSettings.themeSettings.isDarkMode
? const Icon(Icons.dark_mode)
: const Icon(Icons.light_mode),
onToggle: (value) {
ref.read(appSettingsProvider.notifier).toggleDarkMode();
},
),
SettingsTile.switchTile(
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.themeSettings.useMaterialThemeOnItemPage
? const Icon(Icons.auto_fix_high)
: const Icon(Icons.auto_fix_off),
onToggle: (value) {
ref.read(appSettingsProvider.notifier).update(
appSettings.copyWith.themeSettings(
useMaterialThemeOnItemPage: value,
),
);
},
),
],
),
// General section // General section
SettingsSection( SettingsSection(
margin: const EdgeInsetsDirectional.symmetric( margin: const EdgeInsetsDirectional.symmetric(
@ -86,6 +38,16 @@ class AppSettingsPage extends HookConsumerWidget {
style: Theme.of(context).textTheme.titleLarge, style: Theme.of(context).textTheme.titleLarge,
), ),
tiles: [ tiles: [
SettingsTile(
title: const Text('Player Settings'),
leading: const Icon(Icons.play_arrow),
description: const Text(
'Customize the player settings',
),
onPressed: (context) {
context.pushNamed(Routes.playerSettings.name);
},
),
NavigationWithSwitchTile( NavigationWithSwitchTile(
title: const Text('Auto Turn On Sleep Timer'), title: const Text('Auto Turn On Sleep Timer'),
description: const Text( description: const Text(
@ -106,26 +68,6 @@ class AppSettingsPage extends HookConsumerWidget {
); );
}, },
), ),
SettingsTile(
title: const Text('Notification Media Player'),
leading: const Icon(Icons.play_lesson),
description: const Text(
'Customize the media player in notifications',
),
onPressed: (context) {
context.pushNamed(Routes.notificationSettings.name);
},
),
SettingsTile(
title: const Text('Player Settings'),
leading: const Icon(Icons.play_arrow),
description: const Text(
'Customize the player settings',
),
onPressed: (context) {
context.pushNamed(Routes.playerSettings.name);
},
),
NavigationWithSwitchTile( NavigationWithSwitchTile(
title: const Text('Shake Detector'), title: const Text('Shake Detector'),
leading: const Icon(Icons.vibration), leading: const Icon(Icons.vibration),
@ -146,6 +88,41 @@ class AppSettingsPage extends HookConsumerWidget {
), ),
], ],
), ),
// Appearance section
SettingsSection(
margin: const EdgeInsetsDirectional.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
title: Text(
'Appearance',
style: Theme.of(context).textTheme.titleLarge,
),
tiles: [
SettingsTile.navigation(
leading: const Icon(Icons.color_lens),
title: const Text('Theme Settings'),
description: const Text(
'Customize the app theme',
),
onPressed: (context) {
context.pushNamed(Routes.themeSettings.name);
},
),
SettingsTile(
title: const Text('Notification Media Player'),
leading: const Icon(Icons.play_lesson),
description: const Text(
'Customize the media player in notifications',
),
onPressed: (context) {
context.pushNamed(Routes.notificationSettings.name);
},
),
],
),
// Backup and Restore section // Backup and Restore section
SettingsSection( SettingsSection(
margin: const EdgeInsetsDirectional.symmetric( margin: const EdgeInsetsDirectional.symmetric(
@ -185,61 +162,11 @@ class AppSettingsPage extends HookConsumerWidget {
'Restore the app settings from the backup', 'Restore the app settings from the backup',
), ),
onPressed: (context) { onPressed: (context) {
final formKey = GlobalKey<FormState>();
// show a dialog to get the backup // show a dialog to get the backup
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return AlertDialog( return RestoreDialogue();
title: const Text('Restore Backup'),
content: Form(
key: formKey,
child: TextFormField(
controller: serverURIController,
decoration: const InputDecoration(
labelText: 'Backup',
hintText: 'Paste the backup here',
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please paste the backup here';
}
return null;
},
),
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Cancel'),
),
TextButton(
onPressed: () {
if (formKey.currentState!.validate()) {
final backup = serverURIController.text;
final newSettings = model.AppSettings.fromJson(
// decode the backup as json
jsonDecode(backup),
);
ref
.read(appSettingsProvider.notifier)
.update(newSettings);
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Settings restored'),
),
);
// clear the backup
serverURIController.clear();
}
},
child: const Text('Restore'),
),
],
);
}, },
); );
}, },
@ -292,3 +219,83 @@ class AppSettingsPage extends HookConsumerWidget {
); );
} }
} }
class RestoreDialogue extends HookConsumerWidget {
const RestoreDialogue({
super.key,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final formKey = useMemoized(() => GlobalKey<FormState>());
final settings = useState<model.AppSettings?>(null);
final settingsInputController = useTextEditingController();
return AlertDialog(
title: const Text('Restore Backup'),
content: Form(
key: formKey,
child: TextFormField(
autofocus: true,
decoration: InputDecoration(
labelText: 'Backup',
hintText: 'Paste the backup here',
// clear button
suffixIcon: IconButton(
icon: Icon(Icons.clear),
onPressed: () {
settingsInputController.clear();
},
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please paste the backup here';
}
try {
// try to decode the backup
settings.value = model.AppSettings.fromJson(
jsonDecode(value),
);
} catch (e) {
return 'Invalid backup';
}
return null;
},
),
),
actions: [
CancelButton(),
TextButton(
onPressed: () {
if (formKey.currentState!.validate()) {
if (settings.value == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Invalid backup'),
),
);
return;
}
ref.read(appSettingsProvider.notifier).update(settings.value!);
settingsInputController.clear();
Navigator.of(context).pop();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Settings restored'),
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Invalid backup'),
),
);
}
},
child: const Text('Restore'),
),
],
);
}
}

View file

@ -20,12 +20,16 @@ class OkButton<T> extends StatelessWidget {
class CancelButton extends StatelessWidget { class CancelButton extends StatelessWidget {
const CancelButton({ const CancelButton({
super.key, super.key,
this.onPressed,
}); });
final void Function()? onPressed;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return TextButton( return TextButton(
onPressed: () { onPressed: () {
onPressed?.call();
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
child: const Text('Cancel'), child: const Text('Cancel'),

View file

@ -0,0 +1,261 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:vaani/settings/app_settings_provider.dart';
import 'package:vaani/settings/view/buttons.dart';
import 'package:vaani/settings/view/simple_settings_page.dart';
import 'package:vaani/shared/extensions/enum.dart';
class ThemeSettingsPage extends HookConsumerWidget {
const ThemeSettingsPage({
super.key,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final appSettings = ref.watch(appSettingsProvider);
final themeSettings = appSettings.themeSettings;
final primaryColor = Theme.of(context).colorScheme.primary;
return SimpleSettingsPage(
title: const Text('Theme Settings'),
sections: [
SettingsSection(
margin: const EdgeInsetsDirectional.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
tiles: [
// choose system , light or dark theme
SettingsTile.navigation(
title: const Text('Theme Mode'),
description: Text.rich(
TextSpan(
text: themeSettings.themeMode == ThemeMode.system
? 'Using mode from '
: 'Using ',
children: [
TextSpan(
text: themeSettings.themeMode.pascalCase,
style: TextStyle(
color: primaryColor,
),
),
if (themeSettings.themeMode != ThemeMode.system)
const TextSpan(text: ' mode'),
],
),
),
leading: const Icon(Icons.color_lens),
trailing: themeSettings.themeMode == ThemeMode.system
? const Icon(Icons.auto_awesome)
: themeSettings.themeMode == ThemeMode.light
? const Icon(Icons.light_mode)
: const Icon(Icons.dark_mode),
onPressed: (context) async {
final themeMode = await showDialog<ThemeMode>(
context: context,
builder: (context) {
return ModeSelectionDialog(
themeMode: themeSettings.themeMode,
);
},
);
if (themeMode != null) {
ref.read(appSettingsProvider.notifier).update(
appSettings.copyWith.themeSettings(
themeMode: themeMode,
),
);
}
},
),
// high contrast mode
SettingsTile.switchTile(
leading: themeSettings.highContrast
? const Icon(Icons.accessibility)
: const Icon(Icons.accessibility_new_outlined),
initialValue: themeSettings.highContrast,
title: const Text('High Contrast Mode'),
description: const Text(
'Increase the contrast between the background and the text',
),
onToggle: (value) {
ref.read(appSettingsProvider.notifier).update(
appSettings.copyWith.themeSettings(
highContrast: value,
),
);
},
),
// use material theme from system
SettingsTile.switchTile(
initialValue: themeSettings.useMaterialThemeFromSystem,
title: Platform.isAndroid
? const Text('Use Material You')
: const Text('Material Theme from System'),
description: const Text(
'Use the system theme colors for the app',
),
leading: themeSettings.useMaterialThemeFromSystem
? const Icon(Icons.auto_awesome)
: const Icon(Icons.auto_fix_off),
onToggle: (value) {
ref.read(appSettingsProvider.notifier).update(
appSettings.copyWith.themeSettings(
useMaterialThemeFromSystem: value,
),
);
},
),
// TODO choose the primary color
// SettingsTile.navigation(
// title: const Text('Primary Color'),
// description: const Text(
// 'Choose the primary color for the app',
// ),
// leading: const Icon(Icons.colorize),
// trailing: Icon(
// Icons.circle,
// color: themeSettings.customThemeColor.toColor(),
// ),
// onPressed: (context) async {
// final selectedColor = await showDialog<Color>(
// context: context,
// builder: (context) {
// return SimpleDialog(
// title: const Text('Select Primary Color'),
// children: [
// for (final color in Colors.primaries)
// SimpleDialogOption(
// onPressed: () {
// Navigator.pop(context, color);
// },
// child: Container(
// color: color,
// height: 48,
// ),
// ),
// ],
// );
// },
// );
// if (selectedColor != null) {
// ref.read(appSettingsProvider.notifier).update(
// appSettings.copyWith.themeSettings(
// customThemeColor: selectedColor.toHexString(),
// ),
// );
// }
// },
// ),
// use theme throughout the app when playing item
SettingsTile.switchTile(
initialValue: themeSettings.useCurrentPlayerThemeThroughoutApp,
title: const Text('Adapt theme from currently playing item'),
description: const Text(
'Use the theme colors from the currently playing item for the app',
),
leading: themeSettings.useCurrentPlayerThemeThroughoutApp
? const Icon(Icons.auto_fix_high)
: const Icon(Icons.auto_fix_off),
onToggle: (value) {
ref.read(appSettingsProvider.notifier).update(
appSettings.copyWith.themeSettings(
useCurrentPlayerThemeThroughoutApp: value,
),
);
},
),
SettingsTile.switchTile(
initialValue: 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: themeSettings.useMaterialThemeOnItemPage
? const Icon(Icons.auto_fix_high)
: const Icon(Icons.auto_fix_off),
onToggle: (value) {
ref.read(appSettingsProvider.notifier).update(
appSettings.copyWith.themeSettings(
useMaterialThemeOnItemPage: value,
),
);
},
),
],
),
],
);
}
}
extension ColorExtension on Color {
String toHexString() {
return '#${value.toRadixString(16).substring(2)}';
}
}
extension StringExtension on String {
Color toColor() {
return Color(int.parse('0xff$substring(1)'));
}
}
class ModeSelectionDialog extends HookConsumerWidget {
final ThemeMode themeMode;
const ModeSelectionDialog({
super.key,
required this.themeMode,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final selectedTheme = useState(themeMode);
// a wrap of chips to show the available modes with icons
return AlertDialog(
title: const Text('Select Theme Mode'),
content: Wrap(
spacing: 8.0,
runSpacing: 8.0,
children: ThemeMode.values
.map(
(mode) => ChoiceChip(
avatar: switch (mode) {
ThemeMode.system => const Icon(Icons.auto_awesome),
ThemeMode.light => const Icon(Icons.light_mode),
ThemeMode.dark => const Icon(Icons.dark_mode),
},
showCheckmark: false,
label: Text(mode.pascalCase),
selected: mode == selectedTheme.value,
onSelected: (selected) {
if (selected) {
selectedTheme.value = mode;
}
},
),
)
.toList(),
),
actions: [
CancelButton(),
OkButton(
onPressed: () {
Navigator.pop(context, selectedTheme.value);
},
),
],
);
}
}

View file

@ -17,7 +17,7 @@ import 'package:vaani/router/router.dart';
import 'package:vaani/settings/app_settings_provider.dart'; import 'package:vaani/settings/app_settings_provider.dart';
import 'package:vaani/shared/extensions/model_conversions.dart'; import 'package:vaani/shared/extensions/model_conversions.dart';
import 'package:vaani/shared/widgets/shelves/home_shelf.dart'; import 'package:vaani/shared/widgets/shelves/home_shelf.dart';
import 'package:vaani/theme/theme_from_cover_provider.dart'; import 'package:vaani/theme/providers/theme_from_cover_provider.dart';
/// A shelf that displays books on the home page /// A shelf that displays books on the home page
class BookHomeShelf extends HookConsumerWidget { class BookHomeShelf extends HookConsumerWidget {

View file

@ -1,10 +0,0 @@
import 'package:flutter/material.dart';
import 'package:vaani/theme/theme.dart';
final ThemeData darkTheme = ThemeData(
brightness: Brightness.dark,
colorScheme: ColorScheme.fromSeed(
seedColor: brandColor,
brightness: Brightness.dark,
),
);

View file

@ -1,10 +0,0 @@
import 'package:flutter/material.dart';
import 'package:vaani/theme/theme.dart';
final ThemeData lightTheme = ThemeData(
brightness: Brightness.light,
colorScheme: ColorScheme.fromSeed(
seedColor: brandColor,
brightness: Brightness.light,
),
);

View file

@ -0,0 +1,73 @@
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:logging/logging.dart';
import 'package:material_color_utilities/material_color_utilities.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'system_theme_provider.g.dart';
final _logger = Logger('SystemThemeProvider');
/// copied from [DynamicColorBuilder]
@Riverpod(keepAlive: true)
FutureOr<(ColorScheme light, ColorScheme dark)?> systemTheme(
SystemThemeRef ref, {
bool highContrast = false,
}) async {
_logger.fine('Generating system theme');
ColorScheme? schemeLight;
ColorScheme? schemeDark;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
CorePalette? corePalette = await DynamicColorPlugin.getCorePalette();
if (corePalette != null) {
_logger.fine('dynamic_color: Core palette detected.');
schemeLight = corePalette.toColorScheme(brightness: Brightness.light);
schemeDark = corePalette.toColorScheme(brightness: Brightness.dark);
}
} on PlatformException {
_logger.warning('dynamic_color: Failed to obtain core palette.');
}
if (schemeLight == null || schemeDark == null) {
try {
final Color? accentColor = await DynamicColorPlugin.getAccentColor();
if (accentColor != null) {
_logger.fine('dynamic_color: Accent color detected.');
schemeLight = ColorScheme.fromSeed(
seedColor: accentColor,
brightness: Brightness.light,
);
schemeDark = ColorScheme.fromSeed(
seedColor: accentColor,
brightness: Brightness.dark,
);
}
} on PlatformException {
_logger.warning('dynamic_color: Failed to obtain accent color.');
}
}
if (schemeLight == null || schemeDark == null) {
_logger
.warning('dynamic_color: Dynamic color not detected on this device.');
return null;
}
// set high contrast theme
if (highContrast) {
schemeLight = schemeLight
.copyWith(
surface: Colors.white,
)
.harmonized();
schemeDark = schemeDark
.copyWith(
surface: Colors.black,
)
.harmonized();
}
return (schemeLight, schemeDark);
}

View file

@ -0,0 +1,177 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'system_theme_provider.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
String _$systemThemeHash() => r'0af4a012a2a2b2fa91642a1313515cba02cd3535';
/// Copied from Dart SDK
class _SystemHash {
_SystemHash._();
static int combine(int hash, int value) {
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + value);
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
return hash ^ (hash >> 6);
}
static int finish(int hash) {
// ignore: parameter_assignments
hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
// ignore: parameter_assignments
hash = hash ^ (hash >> 11);
return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
}
}
/// copied from [DynamicColorBuilder]
///
/// Copied from [systemTheme].
@ProviderFor(systemTheme)
const systemThemeProvider = SystemThemeFamily();
/// copied from [DynamicColorBuilder]
///
/// Copied from [systemTheme].
class SystemThemeFamily
extends Family<AsyncValue<(ColorScheme light, ColorScheme dark)?>> {
/// copied from [DynamicColorBuilder]
///
/// Copied from [systemTheme].
const SystemThemeFamily();
/// copied from [DynamicColorBuilder]
///
/// Copied from [systemTheme].
SystemThemeProvider call({
bool highContrast = false,
}) {
return SystemThemeProvider(
highContrast: highContrast,
);
}
@override
SystemThemeProvider getProviderOverride(
covariant SystemThemeProvider provider,
) {
return call(
highContrast: provider.highContrast,
);
}
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'systemThemeProvider';
}
/// copied from [DynamicColorBuilder]
///
/// Copied from [systemTheme].
class SystemThemeProvider
extends FutureProvider<(ColorScheme light, ColorScheme dark)?> {
/// copied from [DynamicColorBuilder]
///
/// Copied from [systemTheme].
SystemThemeProvider({
bool highContrast = false,
}) : this._internal(
(ref) => systemTheme(
ref as SystemThemeRef,
highContrast: highContrast,
),
from: systemThemeProvider,
name: r'systemThemeProvider',
debugGetCreateSourceHash:
const bool.fromEnvironment('dart.vm.product')
? null
: _$systemThemeHash,
dependencies: SystemThemeFamily._dependencies,
allTransitiveDependencies:
SystemThemeFamily._allTransitiveDependencies,
highContrast: highContrast,
);
SystemThemeProvider._internal(
super._createNotifier, {
required super.name,
required super.dependencies,
required super.allTransitiveDependencies,
required super.debugGetCreateSourceHash,
required super.from,
required this.highContrast,
}) : super.internal();
final bool highContrast;
@override
Override overrideWith(
FutureOr<(ColorScheme light, ColorScheme dark)?> Function(
SystemThemeRef provider)
create,
) {
return ProviderOverride(
origin: this,
override: SystemThemeProvider._internal(
(ref) => create(ref as SystemThemeRef),
from: from,
name: null,
dependencies: null,
allTransitiveDependencies: null,
debugGetCreateSourceHash: null,
highContrast: highContrast,
),
);
}
@override
FutureProviderElement<(ColorScheme light, ColorScheme dark)?>
createElement() {
return _SystemThemeProviderElement(this);
}
@override
bool operator ==(Object other) {
return other is SystemThemeProvider && other.highContrast == highContrast;
}
@override
int get hashCode {
var hash = _SystemHash.combine(0, runtimeType.hashCode);
hash = _SystemHash.combine(hash, highContrast.hashCode);
return _SystemHash.finish(hash);
}
}
mixin SystemThemeRef
on FutureProviderRef<(ColorScheme light, ColorScheme dark)?> {
/// The parameter `highContrast` of this provider.
bool get highContrast;
}
class _SystemThemeProviderElement
extends FutureProviderElement<(ColorScheme light, ColorScheme dark)?>
with SystemThemeRef {
_SystemThemeProviderElement(super.provider);
@override
bool get highContrast => (origin as SystemThemeProvider).highContrast;
}
// ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View file

@ -1,3 +1,4 @@
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart'; import 'package:flutter_animate/flutter_animate.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
@ -13,15 +14,25 @@ Future<FutureOr<ColorScheme?>> themeFromCover(
ThemeFromCoverRef ref, ThemeFromCoverRef ref,
ImageProvider<Object> img, { ImageProvider<Object> img, {
Brightness brightness = Brightness.dark, Brightness brightness = Brightness.dark,
bool highContrast = false,
}) async { }) async {
// ! add deliberate delay to simulate a long running task as it interferes with other animations // ! add deliberate delay to simulate a long running task as it interferes with other animations
await Future.delayed(500.ms); await Future.delayed(500.ms);
_logger.fine('Generating color scheme from cover image'); _logger.fine('Generating color scheme from cover image');
return ColorScheme.fromImageProvider( var theme = await ColorScheme.fromImageProvider(
provider: img, provider: img,
brightness: brightness, brightness: brightness,
); );
// set high contrast theme
if (highContrast) {
theme = theme
.copyWith(
surface: brightness == Brightness.light ? Colors.white : Colors.black,
)
.harmonized();
}
return theme;
// TODO isolate is not working // TODO isolate is not working
// see https://github.com/flutter/flutter/issues/119207 // see https://github.com/flutter/flutter/issues/119207
// use isolate to generate the color scheme // use isolate to generate the color scheme
@ -50,14 +61,18 @@ FutureOr<ColorScheme?> themeOfLibraryItem(
ThemeOfLibraryItemRef ref, ThemeOfLibraryItemRef ref,
String? itemId, { String? itemId, {
Brightness brightness = Brightness.dark, Brightness brightness = Brightness.dark,
bool highContrast = false,
}) async { }) async {
if (itemId == null) { if (itemId == null) {
return null; return null;
} }
final coverImage = await ref.watch(coverImageProvider(itemId).future); final coverImage = await ref.watch(coverImageProvider(itemId).future);
final val = await ref.watch( final val = await ref.watch(
themeFromCoverProvider(MemoryImage(coverImage), brightness: brightness) themeFromCoverProvider(
.future, MemoryImage(coverImage),
brightness: brightness,
highContrast: highContrast,
).future,
); );
return val; return val;
// coverImage.when( // coverImage.when(

View file

@ -6,7 +6,7 @@ part of 'theme_from_cover_provider.dart';
// RiverpodGenerator // RiverpodGenerator
// ************************************************************************** // **************************************************************************
String _$themeFromCoverHash() => r'a549513a0dcdff76be94488baf38a8b886ce63eb'; String _$themeFromCoverHash() => r'f656614e2d4851acdfa16d249b3198ae0e1d6d6f';
/// Copied from Dart SDK /// Copied from Dart SDK
class _SystemHash { class _SystemHash {
@ -42,10 +42,12 @@ class ThemeFromCoverFamily extends Family<AsyncValue<FutureOr<ColorScheme?>>> {
ThemeFromCoverProvider call( ThemeFromCoverProvider call(
ImageProvider<Object> img, { ImageProvider<Object> img, {
Brightness brightness = Brightness.dark, Brightness brightness = Brightness.dark,
bool highContrast = false,
}) { }) {
return ThemeFromCoverProvider( return ThemeFromCoverProvider(
img, img,
brightness: brightness, brightness: brightness,
highContrast: highContrast,
); );
} }
@ -56,6 +58,7 @@ class ThemeFromCoverFamily extends Family<AsyncValue<FutureOr<ColorScheme?>>> {
return call( return call(
provider.img, provider.img,
brightness: provider.brightness, brightness: provider.brightness,
highContrast: provider.highContrast,
); );
} }
@ -80,11 +83,13 @@ class ThemeFromCoverProvider extends FutureProvider<FutureOr<ColorScheme?>> {
ThemeFromCoverProvider( ThemeFromCoverProvider(
ImageProvider<Object> img, { ImageProvider<Object> img, {
Brightness brightness = Brightness.dark, Brightness brightness = Brightness.dark,
bool highContrast = false,
}) : this._internal( }) : this._internal(
(ref) => themeFromCover( (ref) => themeFromCover(
ref as ThemeFromCoverRef, ref as ThemeFromCoverRef,
img, img,
brightness: brightness, brightness: brightness,
highContrast: highContrast,
), ),
from: themeFromCoverProvider, from: themeFromCoverProvider,
name: r'themeFromCoverProvider', name: r'themeFromCoverProvider',
@ -97,6 +102,7 @@ class ThemeFromCoverProvider extends FutureProvider<FutureOr<ColorScheme?>> {
ThemeFromCoverFamily._allTransitiveDependencies, ThemeFromCoverFamily._allTransitiveDependencies,
img: img, img: img,
brightness: brightness, brightness: brightness,
highContrast: highContrast,
); );
ThemeFromCoverProvider._internal( ThemeFromCoverProvider._internal(
@ -108,10 +114,12 @@ class ThemeFromCoverProvider extends FutureProvider<FutureOr<ColorScheme?>> {
required super.from, required super.from,
required this.img, required this.img,
required this.brightness, required this.brightness,
required this.highContrast,
}) : super.internal(); }) : super.internal();
final ImageProvider<Object> img; final ImageProvider<Object> img;
final Brightness brightness; final Brightness brightness;
final bool highContrast;
@override @override
Override overrideWith( Override overrideWith(
@ -129,6 +137,7 @@ class ThemeFromCoverProvider extends FutureProvider<FutureOr<ColorScheme?>> {
debugGetCreateSourceHash: null, debugGetCreateSourceHash: null,
img: img, img: img,
brightness: brightness, brightness: brightness,
highContrast: highContrast,
), ),
); );
} }
@ -142,7 +151,8 @@ class ThemeFromCoverProvider extends FutureProvider<FutureOr<ColorScheme?>> {
bool operator ==(Object other) { bool operator ==(Object other) {
return other is ThemeFromCoverProvider && return other is ThemeFromCoverProvider &&
other.img == img && other.img == img &&
other.brightness == brightness; other.brightness == brightness &&
other.highContrast == highContrast;
} }
@override @override
@ -150,6 +160,7 @@ class ThemeFromCoverProvider extends FutureProvider<FutureOr<ColorScheme?>> {
var hash = _SystemHash.combine(0, runtimeType.hashCode); var hash = _SystemHash.combine(0, runtimeType.hashCode);
hash = _SystemHash.combine(hash, img.hashCode); hash = _SystemHash.combine(hash, img.hashCode);
hash = _SystemHash.combine(hash, brightness.hashCode); hash = _SystemHash.combine(hash, brightness.hashCode);
hash = _SystemHash.combine(hash, highContrast.hashCode);
return _SystemHash.finish(hash); return _SystemHash.finish(hash);
} }
@ -161,6 +172,9 @@ mixin ThemeFromCoverRef on FutureProviderRef<FutureOr<ColorScheme?>> {
/// The parameter `brightness` of this provider. /// The parameter `brightness` of this provider.
Brightness get brightness; Brightness get brightness;
/// The parameter `highContrast` of this provider.
bool get highContrast;
} }
class _ThemeFromCoverProviderElement class _ThemeFromCoverProviderElement
@ -172,10 +186,12 @@ class _ThemeFromCoverProviderElement
ImageProvider<Object> get img => (origin as ThemeFromCoverProvider).img; ImageProvider<Object> get img => (origin as ThemeFromCoverProvider).img;
@override @override
Brightness get brightness => (origin as ThemeFromCoverProvider).brightness; Brightness get brightness => (origin as ThemeFromCoverProvider).brightness;
@override
bool get highContrast => (origin as ThemeFromCoverProvider).highContrast;
} }
String _$themeOfLibraryItemHash() => String _$themeOfLibraryItemHash() =>
r'a1d0e5d81f4debe88d5a6ce46c3af28623ad4273'; r'b2677daf31a6a53f3f237e5204c62dff5ec43171';
/// See also [themeOfLibraryItem]. /// See also [themeOfLibraryItem].
@ProviderFor(themeOfLibraryItem) @ProviderFor(themeOfLibraryItem)
@ -190,10 +206,12 @@ class ThemeOfLibraryItemFamily extends Family<AsyncValue<ColorScheme?>> {
ThemeOfLibraryItemProvider call( ThemeOfLibraryItemProvider call(
String? itemId, { String? itemId, {
Brightness brightness = Brightness.dark, Brightness brightness = Brightness.dark,
bool highContrast = false,
}) { }) {
return ThemeOfLibraryItemProvider( return ThemeOfLibraryItemProvider(
itemId, itemId,
brightness: brightness, brightness: brightness,
highContrast: highContrast,
); );
} }
@ -204,6 +222,7 @@ class ThemeOfLibraryItemFamily extends Family<AsyncValue<ColorScheme?>> {
return call( return call(
provider.itemId, provider.itemId,
brightness: provider.brightness, brightness: provider.brightness,
highContrast: provider.highContrast,
); );
} }
@ -228,11 +247,13 @@ class ThemeOfLibraryItemProvider extends FutureProvider<ColorScheme?> {
ThemeOfLibraryItemProvider( ThemeOfLibraryItemProvider(
String? itemId, { String? itemId, {
Brightness brightness = Brightness.dark, Brightness brightness = Brightness.dark,
bool highContrast = false,
}) : this._internal( }) : this._internal(
(ref) => themeOfLibraryItem( (ref) => themeOfLibraryItem(
ref as ThemeOfLibraryItemRef, ref as ThemeOfLibraryItemRef,
itemId, itemId,
brightness: brightness, brightness: brightness,
highContrast: highContrast,
), ),
from: themeOfLibraryItemProvider, from: themeOfLibraryItemProvider,
name: r'themeOfLibraryItemProvider', name: r'themeOfLibraryItemProvider',
@ -245,6 +266,7 @@ class ThemeOfLibraryItemProvider extends FutureProvider<ColorScheme?> {
ThemeOfLibraryItemFamily._allTransitiveDependencies, ThemeOfLibraryItemFamily._allTransitiveDependencies,
itemId: itemId, itemId: itemId,
brightness: brightness, brightness: brightness,
highContrast: highContrast,
); );
ThemeOfLibraryItemProvider._internal( ThemeOfLibraryItemProvider._internal(
@ -256,10 +278,12 @@ class ThemeOfLibraryItemProvider extends FutureProvider<ColorScheme?> {
required super.from, required super.from,
required this.itemId, required this.itemId,
required this.brightness, required this.brightness,
required this.highContrast,
}) : super.internal(); }) : super.internal();
final String? itemId; final String? itemId;
final Brightness brightness; final Brightness brightness;
final bool highContrast;
@override @override
Override overrideWith( Override overrideWith(
@ -276,6 +300,7 @@ class ThemeOfLibraryItemProvider extends FutureProvider<ColorScheme?> {
debugGetCreateSourceHash: null, debugGetCreateSourceHash: null,
itemId: itemId, itemId: itemId,
brightness: brightness, brightness: brightness,
highContrast: highContrast,
), ),
); );
} }
@ -289,7 +314,8 @@ class ThemeOfLibraryItemProvider extends FutureProvider<ColorScheme?> {
bool operator ==(Object other) { bool operator ==(Object other) {
return other is ThemeOfLibraryItemProvider && return other is ThemeOfLibraryItemProvider &&
other.itemId == itemId && other.itemId == itemId &&
other.brightness == brightness; other.brightness == brightness &&
other.highContrast == highContrast;
} }
@override @override
@ -297,6 +323,7 @@ class ThemeOfLibraryItemProvider extends FutureProvider<ColorScheme?> {
var hash = _SystemHash.combine(0, runtimeType.hashCode); var hash = _SystemHash.combine(0, runtimeType.hashCode);
hash = _SystemHash.combine(hash, itemId.hashCode); hash = _SystemHash.combine(hash, itemId.hashCode);
hash = _SystemHash.combine(hash, brightness.hashCode); hash = _SystemHash.combine(hash, brightness.hashCode);
hash = _SystemHash.combine(hash, highContrast.hashCode);
return _SystemHash.finish(hash); return _SystemHash.finish(hash);
} }
@ -308,6 +335,9 @@ mixin ThemeOfLibraryItemRef on FutureProviderRef<ColorScheme?> {
/// The parameter `brightness` of this provider. /// The parameter `brightness` of this provider.
Brightness get brightness; Brightness get brightness;
/// The parameter `highContrast` of this provider.
bool get highContrast;
} }
class _ThemeOfLibraryItemProviderElement class _ThemeOfLibraryItemProviderElement
@ -319,6 +349,8 @@ class _ThemeOfLibraryItemProviderElement
@override @override
Brightness get brightness => Brightness get brightness =>
(origin as ThemeOfLibraryItemProvider).brightness; (origin as ThemeOfLibraryItemProvider).brightness;
@override
bool get highContrast => (origin as ThemeOfLibraryItemProvider).highContrast;
} }
// ignore_for_file: type=lint // ignore_for_file: type=lint
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member // ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member

View file

@ -1,9 +1,15 @@
import 'dart:ui'; import 'package:flutter/material.dart';
export 'dark.dart';
export 'light.dart';
// brand color rgb(49, 27, 146) rgb(96, 76, 236) // brand color rgb(49, 27, 146) rgb(96, 76, 236)
const brandColor = Color(0xFF311B92); const brandColor = Color(0xFF311B92);
const brandColorLight = Color(0xFF604CEC); const brandColorLight = Color(0xFF604CEC);
final brandLightColorScheme = ColorScheme.fromSeed(
seedColor: brandColor,
brightness: Brightness.light,
);
final brandDarkColorScheme = ColorScheme.fromSeed(
seedColor: brandColor,
brightness: Brightness.dark,
);

View file

@ -6,11 +6,15 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin.h>
#include <isar_flutter_libs/isar_flutter_libs_plugin.h> #include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <media_kit_libs_linux/media_kit_libs_linux_plugin.h> #include <media_kit_libs_linux/media_kit_libs_linux_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h> #include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
g_autoptr(FlPluginRegistrar) isar_flutter_libs_registrar = g_autoptr(FlPluginRegistrar) isar_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "IsarFlutterLibsPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "IsarFlutterLibsPlugin");
isar_flutter_libs_plugin_register_with_registrar(isar_flutter_libs_registrar); isar_flutter_libs_plugin_register_with_registrar(isar_flutter_libs_registrar);

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
isar_flutter_libs isar_flutter_libs
media_kit_libs_linux media_kit_libs_linux
url_launcher_linux url_launcher_linux

View file

@ -390,6 +390,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
dynamic_color:
dependency: "direct main"
description:
name: dynamic_color
sha256: eae98052fa6e2826bdac3dd2e921c6ce2903be15c6b7f8b6d8a5d49b5086298d
url: "https://pub.dev"
source: hosted
version: "1.7.0"
easy_stepper: easy_stepper:
dependency: "direct main" dependency: "direct main"
description: description:

View file

@ -44,6 +44,7 @@ dependencies:
cupertino_icons: ^1.0.6 cupertino_icons: ^1.0.6
device_info_plus: ^10.1.0 device_info_plus: ^10.1.0
duration_picker: ^1.2.0 duration_picker: ^1.2.0
dynamic_color: ^1.7.0
easy_stepper: ^0.8.4 easy_stepper: ^0.8.4
file_picker: ^8.1.2 file_picker: ^8.1.2
flutter: flutter:

View file

@ -6,6 +6,7 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <dynamic_color/dynamic_color_plugin_c_api.h>
#include <isar_flutter_libs/isar_flutter_libs_plugin.h> #include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <media_kit_libs_windows_audio/media_kit_libs_windows_audio_plugin_c_api.h> #include <media_kit_libs_windows_audio/media_kit_libs_windows_audio_plugin_c_api.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h> #include <permission_handler_windows/permission_handler_windows_plugin.h>
@ -13,6 +14,8 @@
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
DynamicColorPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
IsarFlutterLibsPluginRegisterWithRegistrar( IsarFlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("IsarFlutterLibsPlugin")); registry->GetRegistrarForPlugin("IsarFlutterLibsPlugin"));
MediaKitLibsWindowsAudioPluginCApiRegisterWithRegistrar( MediaKitLibsWindowsAudioPluginCApiRegisterWithRegistrar(

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
dynamic_color
isar_flutter_libs isar_flutter_libs
media_kit_libs_windows_audio media_kit_libs_windows_audio
permission_handler_windows permission_handler_windows