|
| 1 | +--- |
| 2 | +title: 'Guide: Customizing the UI Theme' |
| 3 | +description: A practical, step-by-step guide to customizing the UI theme by taking ownership of the ui_kit package. |
| 4 | +--- |
| 5 | +import { Steps, Aside } from '@astrojs/starlight/components'; |
| 6 | + |
| 7 | +This guide provides a hands-on, practical walkthrough of the most common and impactful customization task: changing the application's visual theme. |
| 8 | + |
| 9 | +By following this guide, you will learn the complete, end-to-end workflow for modifying a shared package and seeing that change reflected in both the Mobile Client and the Web Dashboard. This process is the key to unlocking the full customization potential of the toolkit. |
| 10 | + |
| 11 | +### The Goal |
| 12 | + |
| 13 | +Our goal is to change the default blue accent color of the application to a new color, for example, deep purple. To do this, we will take ownership of the `ui_kit` package, modify its theme file, and then instruct both of our Flutter applications to use our modified version. |
| 14 | + |
| 15 | +<Steps> |
| 16 | +1. **Take Ownership of the `ui_kit` Package** |
| 17 | + |
| 18 | + Before you can change any code, you must have your own version of the `ui_kit` package hosted in a private repository. |
| 19 | + |
| 20 | + - Follow the [**Taking Ownership of Packages**](/docs/architecture/02-taking-ownership-of-packages/) guide from start to finish, but for the `ui_kit` repository. |
| 21 | + - **Clone URL:** `https://github.com/flutter-news-app-full-source-code/ui-kit.git` |
| 22 | + |
| 23 | + Once you have successfully pushed the `ui_kit` code to your own private GitHub repository, you are ready to proceed. |
| 24 | + |
| 25 | +2. **Modify the Theme Code** |
| 26 | + |
| 27 | + Now, open the `ui_kit` package you cloned to your local machine in your code editor (e.g., VS Code). |
| 28 | + |
| 29 | + - Navigate to and open the file: `lib/src/theme/app_theme.dart`. |
| 30 | + - Locate the `_commonSubThemesData` constant. This is where you can make global changes to widget styles. |
| 31 | + - Let's change the `appBarBackgroundSchemeColor` to `primary` to make the app bar more prominent. |
| 32 | + |
| 33 | + ```dart title="packages/ui-kit/lib/src/theme/app_theme.dart" |
| 34 | + const FlexSubThemesData _commonSubThemesData = FlexSubThemesData( |
| 35 | + // ... |
| 36 | + // Change the app bar background color |
| 37 | + appBarBackgroundSchemeColor: SchemeColor.primary, // Changed from .surface |
| 38 | + // ... |
| 39 | + ); |
| 40 | + ``` |
| 41 | + |
| 42 | +3. **Commit and Push Your Changes** |
| 43 | + |
| 44 | + Save the file, then commit and push this change to *your private* `ui_kit` repository. |
| 45 | + |
| 46 | + ```bash |
| 47 | + # From inside your local ui_kit directory |
| 48 | + git add . |
| 49 | + git commit -m "feat: change app bar theme color" |
| 50 | + git push |
| 51 | + ``` |
| 52 | + |
| 53 | +4. **Update the Mobile Client** |
| 54 | + |
| 55 | + Now it's time to see your change in action. Open the **Mobile Client** project (`flutter-news-app-mobile-client-full-source-code`) in your code editor. |
| 56 | + |
| 57 | + - Open the `pubspec.yaml` file. |
| 58 | + - Locate the `ui_kit` dependency. |
| 59 | + - Change the `url` to point to your private repository's URL. |
| 60 | + |
| 61 | + ```yaml title="Mobile Client's pubspec.yaml" |
| 62 | + dependencies: |
| 63 | + # ... other dependencies |
| 64 | + ui_kit: |
| 65 | + git: |
| 66 | + # Replace this with the URL of YOUR private repository |
| 67 | + url: https://github.com/YOUR_USERNAME/YOUR_UI_KIT_REPO.git |
| 68 | + # ... other dependencies |
| 69 | + ``` |
| 70 | + |
| 71 | + - Now, run `flutter pub upgrade` in the terminal for the Mobile Client project. This will fetch the updated code from your private repository. |
| 72 | + |
| 73 | + ```bash |
| 74 | + flutter pub upgrade ui_kit |
| 75 | + ``` |
| 76 | + |
| 77 | + - Relaunch the mobile app (`flutter run`). You should now see your new theme color applied to the app bar! |
| 78 | + |
| 79 | +5. **Update the Web Dashboard** |
| 80 | + |
| 81 | + The final step is to apply the exact same change to the Web Dashboard, demonstrating the power of the shared package. |
| 82 | + |
| 83 | + - Open the **Web Dashboard** project (`flutter-news-app-web-dashboard-full-source-code`). |
| 84 | + - Open its `pubspec.yaml` file. |
| 85 | + - Update the `ui_kit` dependency's `url` to point to your private repository, just as you did for the mobile client. |
| 86 | + - Run `flutter pub upgrade ui_kit` in the terminal for the Web Dashboard project. |
| 87 | + - Relaunch the web app (`flutter run -d chrome`). The dashboard will now also have the new app bar color. |
| 88 | + |
| 89 | +</Steps> |
| 90 | + |
| 91 | +### Conclusion |
| 92 | + |
| 93 | +You have successfully completed the core customization workflow. You now have a privately owned and modified `ui_kit` package that is consumed by both of your client applications. You can use this exact same process to customize any other shared package in the toolkit. |
0 commit comments