mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-30 11:54:22 +01:00
* Add theme base v2 * Initial new theme base files * Typos * Fixes * Update theme files * feat: Migrate to Material 3 Theming Foundation, Theme Data Refactor, and First Extension Cleanup Batch. This commit completes the first major phase of migrating to Material 3 theming by setting up the foundations for material 3 integration and begins the initial migration, removing custom theme extensions, updating theme data, and refactoring all relevant widget and page theming to use Material 3’s built-in color and typography tokens. These changes: - Lays the groundwork for Material 3 theming by restructuring the app’s theme configuration to use Material 3’s ColorScheme and TextTheme as the primary sources of color and typography throughout the app. - Refactors the core theme config files by removing legacy custom color roles ensuring all color definitions now map directly to Material 3’s role. - Begins the first batch migration of custom theme extensions (InfoTheme, PlaceholderTheme, KeyboardTheme, PinCodeTheme) and updates all affected widgets and pages to use Material 3 color and typography tokens instead of the custom properties. - Cleans up the codebase by deleting the files of the initial set of migrated extensions and eliminating all related imports and usages. * feat: Migrate to Material 3 Theming. This change: - Updates the themes README.md file to reflect the current structure and give more information based on the first major phase that was completed. * feat: Migrate to Material 3 Theming Deleting previous theme extensions * feat: Migrate to Material 3 Theming Another batch of migrations from existing extensions * feat: Migration to Material 3 Theming Third Migration batch for theme extensions * fwat: Migration to Material 3 Theming Final Migration batch for previous theme extensions * Update onboarding hero * Update button radius * Add surfaceContainer to light theme * feat(themes): Migrate to Material 3 Theming This change: - Adds new set of hero images - Modifies the core structure for the themes - Add missing color tokens to the theme classes - Adds a CustomThemeColor class for custom color tokens - Modifies the themelist to have a fall back for previous theme implementation - Adds localization for some texts - Modifies the flow for loading the theme on app start - Add a WidgetsBindingObserver that listens for changes in the device theme and updates the app theme when there is a change - Registers the themeStore as a Singleton for codebase wide use * feat(themes): Migrate to Material 3 theming This change: - Migrates UI flows across the app to the new themes - Confirms styling and typography of components across the app uses the new themes - Remove instances of Palette use - Switch TextStyles across the app to use theme text styles * feat(themes): Migrate to Material 3 Theming. This change: - Adjusts bottomsheets styling and removes duplicate close button - Removes more themedata extensions from the previous implementation * - Remove outlines from cards and dock - Update menu colors - Update padding/divider size for cards * - Update PIN screen - Fix navigation dock shadow - Update wallet screen colors * Update border radius --skip-ci * feat(themes): Migrate to Material 3 Theming. This change: - Adds gradient backgrounds to the dashbaord and balance cards. - Migrates the input fields across the app to BaseTextFormFields. - Removes dependence of input fields on individual styling, focusing instead on using theme defined InputDecoration styling with adjustments on individual components where needed. - Applies new theme styling to BaseTextFormField, AddressTextField and CurrencyAmountTextField. * - Switch some hero images to PNG - Fix nagivation_dock shadow - Minor fixes * feat: Add fallback to previous underline styling in central widgets This change: - Adds a fallback to CurrencyAmountTextField, AddressTextField, and BaseTextFormField, allowing them use the previous theme styling. - Adds localization for new texts * feat(themes): Update warning box colors for dark and light themes * feat(themes): Relaod themes when user restores from backup, ensuring the user previous theme preference is used. * feat(themes): Handle themes logic during restore from backup This change: - Refactors theme loading logic to handle backup restore edgecase - Refreshes the theme based on the user saved preference during restore from backup flow * Fix card gradients and spacing * Fix even more radiuses Test new icons for navigation_dock.dart * Update onboarding flow backgrounds Fix swap icon clipping Fix some text colors Add more hero images * Fix incorrect color for light theme * Fix more hero images and cleanup * Update text field icons Fix info box CTA colors Fix sync indicator colors * Update toggle colors Update dark theme colors (minor) Update crypto_balance_widget.dart icon * Update page transitions in router.dart Fix some colors * feat(themes): Display label by default for filled textfields * feat(themes): Refactor theme handling across various components This change: - Fixes issue with themeMode resetting to system mode when app is restarted causing a UI glitch - Updates theme checks from `currentTheme.type == ThemeType.dark` to `currentTheme.isDark` for consistency - Adjusts UI components to use the theme directly from the themeStore * feat(themes): Add animating tagline to the create pin welcome screen * Revert text fields label temporarily, fix a couple colors, and cleanup some images --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com> Co-authored-by: Blazebrain <davidadegoke16@gmail.com>
161 lines
4.5 KiB
Dart
161 lines
4.5 KiB
Dart
import 'package:cake_wallet/entities/preferences_key.dart';
|
|
import 'package:cake_wallet/utils/device_info.dart';
|
|
import 'package:cake_wallet/utils/responsive_layout_util.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cake_wallet/themes/utils/theme_list.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'material_base_theme.dart';
|
|
|
|
part 'theme_store.g.dart';
|
|
|
|
/// MobX store for managing theme state
|
|
class ThemeStore = ThemeStoreBase with _$ThemeStore;
|
|
|
|
abstract class ThemeStoreBase with Store {
|
|
@observable
|
|
MaterialThemeBase _currentTheme = ThemeList.lightTheme;
|
|
|
|
@observable
|
|
ThemeMode _themeMode = ThemeMode.system;
|
|
|
|
@computed
|
|
MaterialThemeBase get currentTheme => _currentTheme;
|
|
|
|
@computed
|
|
ThemeMode get themeMode => _themeMode;
|
|
|
|
@computed
|
|
bool get isDarkMode => _currentTheme.isDark;
|
|
|
|
late SharedPreferences sharedPreferences;
|
|
|
|
@action
|
|
Future<void> setTheme(MaterialThemeBase theme) async {
|
|
if (_currentTheme == theme) return;
|
|
|
|
_currentTheme = theme;
|
|
await sharedPreferences.setInt(PreferencesKey.currentTheme, theme.raw);
|
|
}
|
|
|
|
@action
|
|
Future<void> setThemeMode(ThemeMode mode, {bool shouldRefreshTheme = true}) async {
|
|
if (_themeMode == mode) return;
|
|
|
|
_themeMode = mode;
|
|
await sharedPreferences.setString(PreferencesKey.themeMode, mode.toString());
|
|
|
|
if (mode == ThemeMode.system && shouldRefreshTheme) {
|
|
setTheme(getThemeFromSystem());
|
|
}
|
|
}
|
|
|
|
/// Loads the saved theme preferences
|
|
Future<void> loadThemePreferences() async {
|
|
sharedPreferences = await SharedPreferences.getInstance();
|
|
|
|
await _loadThemeMode();
|
|
await _loadAndSetTheme();
|
|
|
|
_setupThemeReaction();
|
|
}
|
|
|
|
/// Loads the saved theme mode from SharedPreferences
|
|
Future<void> _loadThemeMode() async {
|
|
final savedThemeMode = sharedPreferences.getString(PreferencesKey.themeMode);
|
|
if (savedThemeMode != null) {
|
|
_themeMode = ThemeMode.values.firstWhere(
|
|
(mode) => mode.toString() == savedThemeMode,
|
|
orElse: () => ThemeMode.system,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Loads and sets the appropriate theme based on platform and installation status
|
|
Future<void> _loadAndSetTheme() async {
|
|
final bool isNewInstall = sharedPreferences.getBool(PreferencesKey.isNewInstall) ?? true;
|
|
|
|
bool shouldUseMobileTheme =
|
|
responsiveLayoutUtil.shouldRenderMobileUI && DeviceInfo.instance.isMobile;
|
|
|
|
if (shouldUseMobileTheme) {
|
|
await _handleMobileTheme(isNewInstall);
|
|
} else {
|
|
await _handleNonMobileTheme();
|
|
}
|
|
}
|
|
|
|
/// Handles theme loading for non-mobile platforms
|
|
Future<void> _handleNonMobileTheme() async {
|
|
await setTheme(ThemeList.darkTheme);
|
|
await setThemeMode(ThemeMode.dark);
|
|
}
|
|
|
|
/// Handles theme loading for mobile platforms
|
|
Future<void> _handleMobileTheme(bool isNewInstall) async {
|
|
if (isNewInstall) {
|
|
await _setSystemTheme();
|
|
} else {
|
|
await loadSavedTheme();
|
|
}
|
|
}
|
|
|
|
/// Loads the saved theme from SharedPreferences
|
|
Future<void> loadSavedTheme({bool isFromBackup = false}) async {
|
|
try {
|
|
final savedTheme = sharedPreferences.getInt(PreferencesKey.currentTheme);
|
|
if (savedTheme == null) {
|
|
await _setSystemTheme();
|
|
return;
|
|
}
|
|
|
|
final theme = ThemeList.deserialize(raw: savedTheme);
|
|
|
|
if (_currentTheme != theme) {
|
|
await setTheme(theme);
|
|
}
|
|
|
|
final newThemeMode = _getThemeModeOnStartUp(theme, isFromBackup);
|
|
|
|
if (_themeMode != newThemeMode) {
|
|
await setThemeMode(newThemeMode, shouldRefreshTheme: false);
|
|
}
|
|
} catch (e) {
|
|
await _setSystemTheme();
|
|
}
|
|
}
|
|
|
|
Future<void> _setSystemTheme() async {
|
|
final systemTheme = getThemeFromSystem();
|
|
|
|
if (_currentTheme != systemTheme) {
|
|
await setTheme(systemTheme);
|
|
}
|
|
|
|
if (_themeMode != ThemeMode.system) {
|
|
await setThemeMode(ThemeMode.system);
|
|
}
|
|
}
|
|
|
|
ThemeMode _getThemeModeOnStartUp(MaterialThemeBase theme, bool isFromBackup) {
|
|
if (isFromBackup || _themeMode != ThemeMode.system) {
|
|
return theme.isDark ? ThemeMode.dark : ThemeMode.light;
|
|
}
|
|
|
|
return ThemeMode.system;
|
|
}
|
|
|
|
void _setupThemeReaction() {
|
|
reaction(
|
|
(_) => currentTheme,
|
|
(MaterialThemeBase theme) => sharedPreferences.setInt(PreferencesKey.currentTheme, theme.raw),
|
|
);
|
|
}
|
|
|
|
MaterialThemeBase getThemeFromSystem() {
|
|
final systemBrightness = WidgetsBinding.instance.window.platformBrightness;
|
|
return systemBrightness == Brightness.dark ? ThemeList.darkTheme : ThemeList.lightTheme;
|
|
}
|
|
}
|