feat(app): allow a host to inject theme and feature config#1442
Closed
SERDUN wants to merge 4 commits into
Closed
Conversation
Add optional ThemeSettings, ThemeMode and FeatureAccess parameters to RootApp. When a host (the theme configurator's realtime preview) mounts the app in-process it supplies them; they are provided down the tree as plain values so the app renders the host's config instead of its bootstrap-built defaults: - FeatureAccess: a host-supplied value replaces the reactive StreamProvider. - ThemeSettings / ThemeMode: provided as nullable values; App pushes a non-null host theme into the AppBloc (AppThemeSettingsChanged / AppThemeModeChanged) in didChangeDependencies, keeping AppState the single source of truth for theme. All parameters are null in a normal standalone run, where behaviour is unchanged.
The realtime preview pushed the host theme mode through AppThemeModeChanged, whose handler writes it into themeModeRepository (setThemeMode/clear). An ephemeral preview therefore overwrote the device's saved theme-mode preference, so the real app booted in the previewed mode afterwards. Add a non-persisting AppThemeModePreviewed event that only emits the mode into AppState, and dispatch it for host-supplied modes. Theme settings already used a pure emit, so only the mode path needed this. The handler is synchronous and registered without droppable(), so rapid preview toggles are no longer dropped.
This reverts commit 02b8e0d.
Drop the separate themeMode injection parameter from RootApp. The app already treats featureAccess.supportedConfig.themeMode as the authoritative theme mode (build() derives finalThemeMode from it), and a host always supplies featureAccess, so a parallel themeMode path was redundant. It was also the only host-config path that persisted: it dispatched AppThemeModeChanged, whose handler writes to themeModeRepository. The app runs either standalone (config from local storage) or embedded in a host that provides the config - never both - so this never corrupted a real preference, but routing the mode through featureAccess keeps a single, non-persisting source for it. Host theme settings still flow through AppThemeSettingsChanged (a pure emit).
Member
Author
|
Closing in favour of a cleaner approach: RootApp as the single injection boundary, everything below consuming via inherited providers (theme lifted out of the AppState render path). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Lets an external host that mounts this app in-process — the theme configurator's realtime preview — supply the theme and feature config it should render, instead of the app's own bootstrap-built defaults.
This is the second of two PRs split out of the embedding work (the first, #1441, makes Firebase optional). The two are independent; the realtime preview consumes both.
Changes
main.dart—RootAppgains optionalthemeSettings,themeModeandfeatureAccessparameters, provided down the tree:FeatureAccess— a host-supplied value replaces the reactiveStreamProvider; otherwise the stream is used as before.ThemeSettings?/ThemeMode?— provided as nullable values (null in a normal run).app.dart— when a non-null host theme is present,Apppushes it into theAppBloc(AppThemeSettingsChanged/AppThemeModeChanged) indidChangeDependencies, soAppStatestays the single source of truth for theme — no parallel override path, no streams smeared through the widget tree.Verification
flutter analyze— clean.