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

@ -1,3 +1,4 @@
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.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/playback_reporting/providers/playback_reporter_provider.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/sleep_timer/providers/sleep_timer_provider.dart';
import 'package:vaani/router/router.dart';
import 'package:vaani/settings/api_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';
final appLogger = Logger('vaani');
@ -51,16 +55,77 @@ class MyApp extends ConsumerWidget {
if (needOnboarding) {
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 {
return MaterialApp.router(
// debugShowCheckedModeBanner: false,
theme: lightTheme,
darkTheme: darkTheme,
themeMode: ref.watch(appSettingsProvider).themeSettings.isDarkMode
? ThemeMode.dark
: ThemeMode.light,
theme: appThemeLight,
darkTheme: appThemeDark,
themeMode: themeSettings.themeMode,
routerConfig: routerConfig,
themeAnimationCurve: Curves.easeInOut,
);
} catch (e) {
debugPrintStack(stackTrace: StackTrace.current, label: e.toString());