|
| 1 | +--- |
| 2 | +title: 'Guide: Styling & Theming' |
| 3 | +description: Learn how to customize the application's visual appearance. |
| 4 | +--- |
| 5 | +import { Card, CardGrid, Aside } from '@astrojs/starlight/components'; |
| 6 | + |
| 7 | +The mobile client's visual appearance is managed by a centralized theming system located in the `ui_kit` package. This allows for consistent styling and easy customization of the app's look and feel. The system is built on top of the powerful `flex_color_scheme` package. |
| 8 | + |
| 9 | +### Core Theming Files |
| 10 | + |
| 11 | +All theme-related logic is located in `packages/ui-kit/lib/src/theme/app_theme.dart`. This file contains: |
| 12 | + |
| 13 | +- **`lightTheme()` and `darkTheme()`**: These functions generate the `ThemeData` for the light and dark modes of the application. |
| 14 | +- **`_commonSubThemesData`**: A constant that defines shared customizations for common widgets like `Card`, `AppBar`, and `InputDecorator`. |
| 15 | +- **`_customizeTextTheme()`**: A helper function that applies user-selected font sizes and weights to the base `TextTheme`. |
| 16 | +- **`_getGoogleFontTextTheme()`**: A helper that maps a font family name (e.g., "Roboto") to the corresponding text theme function from the `google_fonts` package. |
| 17 | + |
| 18 | +### How to Customize the Theme |
| 19 | + |
| 20 | +#### 1. Changing Colors |
| 21 | + |
| 22 | +The application uses predefined color schemes from `FlexColorScheme`. You can change the active color scheme by modifying the `AppAccentTheme` enum in `packages/core/lib/src/enums/app_enums.dart` and updating the `_mapAppAccentTheme` helper in `lib/app/bloc/app_bloc.dart`. |
| 23 | + |
| 24 | +To add a completely new custom color scheme: |
| 25 | +1. Define your custom `FlexSchemeData` in `app_theme.dart`. |
| 26 | +2. Add a new value to the `AppAccentTheme` enum. |
| 27 | +3. Update the `_mapAppAccentTheme` helper in `AppBloc` to map your new enum value to your custom scheme. |
| 28 | + |
| 29 | +#### 2. Customizing Widget Styles |
| 30 | + |
| 31 | +You can change the default appearance of common widgets by modifying the `_commonSubThemesData` constant in `app_theme.dart`. |
| 32 | + |
| 33 | +For example, to change the default elevation of all cards in the app: |
| 34 | + |
| 35 | +```dart title="packages/ui-kit/lib/src/theme/app_theme.dart" |
| 36 | +const FlexSubThemesData _commonSubThemesData = FlexSubThemesData( |
| 37 | + // ... |
| 38 | + cardElevation: 4.0, |
| 39 | + // ... |
| 40 | +); |
| 41 | +``` |
| 42 | + |
| 43 | +#### 3. Adding a New Font |
| 44 | + |
| 45 | +To make a new font available for users to select: |
| 46 | +1. Add the font to your project assets and declare it in `pubspec.yaml`. |
| 47 | +2. Add the new font name to the list of available fonts in `lib/settings/view/font_settings_page.dart`. |
| 48 | +3. Update the `_getGoogleFontTextTheme` helper in `app_theme.dart` to map the new font name to its `GoogleFonts` text theme function. |
| 49 | + |
| 50 | +<Aside> |
| 51 | +For a deep dive into the capabilities of `flex_color_scheme`, please refer to its excellent [official documentation](https://docs.flexcolorscheme.com/). |
| 52 | +</Aside> |
0 commit comments