feat(config): make EnvironmentConfig runtime-overridable#1435
Merged
Conversation
Convert EnvironmentConfig's compile-time *.fromEnvironment constants into getters that resolve `runtime override ?? compile-time default`, and add applyOverrides/clearOverrides/hasOverride. This lets an embedder (e.g. the theme configurator's realtime preview) inject the whole dart-define set at runtime. Standalone builds are byte-identical - no overrides are ever applied. The *__NAME key constants stay const. Nullable `bool.hasEnvironment(X) ? String.fromEnvironment(X) : null` fallbacks move to `static const _*_ENV` fields, since hasEnvironment can only be used in a const context. Members become getters, so const-context usages are adjusted (const -> final / drop const): main_shell.dart polling Durations, feature_access.dart CallTriggerConfig, logzio_logging_service.dart, autoprovision, push_tokens, several screen-page titles, and the screenshots subpackage (router + test + main_screen_screenshot).
2fdd5b3 to
9e857d2
Compare
Route every EnvironmentConfig getter through a single EnvRegistry instance that owns the override store and the typed override-first resolution (string/stringOrNull/boolean/integer). Getters now only declare a key + a compile-time default and ask the registry for the value - they no longer touch the override map or know whether a value came from a runtime override or the compile-time dart-define. applyOverrides/clearOverrides/hasOverride delegate to the registry. No behaviour change.
Polling intervals are runtime-overridable getters fed into Duration(seconds:). A 0 or negative override produced a zero-delay periodic poller (request storm) or a negative-Duration assertion. Resolve every *_POLLING_INTERVAL_SECONDS getter through _pollingSeconds(), which falls back to the compile-time default when the override is non-positive.
REMOTE_LOGZIO_LOG_LEVEL is runtime-overridable; an override that is not an exact Level name made Level.LEVELS.firstWhere throw StateError and crash logging setup. Add an orElse that warns and falls back to Level.INFO.
EnvRegistry.string/stringOrNull returned an empty-string override verbatim, so
an embedder passing WEBTRIT_APP_NAME='' produced blank titles and
WEBTRIT_APP_DEMO_CORE_URL='' made Uri.parse('') the fallback core URL. A blank
dart-define means "not set", so empty overrides now fall back to the
compile-time default.
EnvRegistry.boolean/integer silently coerced malformed overrides ('yes' -> false,
'abc' -> default), so an operator's toggle could be ignored with no diagnostic.
Honour 'true'/'false' and numeric values, treat empty as unset, and log a
warning before falling back for anything else.
Add unit tests for the runtime-override mechanism that previously shipped untested: EnvRegistry string/stringOrNull/boolean/integer (override-wins, empty-as-unset, malformed-fallback), has/clear, and EnvironmentConfig applyOverrides/clearOverrides incl. the non-positive polling-interval guard.
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
Convert
EnvironmentConfig's compile-time*.fromEnvironmentconstants into getters that resolveruntime override ?? compile-time default, and addapplyOverrides/clearOverrides/hasOverride. This lets an embedder (the theme configurator's realtime preview) inject the whole dart-define set at runtime. The*__NAMEkey constants stayconst.Nullable
bool.hasEnvironment(X) ? String.fromEnvironment(X) : nullfallbacks move tostatic const _*_ENVfields, sincebool.hasEnvironmentcan only be used in a const context.Because members become getters (not compile-time constants), const-context usages are adjusted (
const->final/ dropconst):main_shell.dartpollingDurations,feature_access.dartCallTriggerConfig,logzio_logging_service.dart, autoprovision, push_tokens, several screen-page titles, and thescreenshotssubpackage (router + integration test + main_screen_screenshot).Why
Independent enabler for the realtime-preview epic. On its own it changes nothing observable — standalone builds never call
applyOverrides, so every value resolves to the same compile-time default as before.Notes
flutter analyze liband thescreenshotssubpackage both green.