Skip to content

Commit 9e857d2

Browse files
committed
feat(config): make EnvironmentConfig runtime-overridable
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).
1 parent cda213e commit 9e857d2

17 files changed

Lines changed: 149 additions & 81 deletions

File tree

lib/app/router/main_shell.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -739,36 +739,36 @@ class _MainShellState extends State<MainShell> with WidgetsBindingObserver {
739739
return [
740740
PollingRegistration(
741741
listener: context.read<UserRepository>(),
742-
interval: const Duration(seconds: EnvironmentConfig.USER_REPOSITORY_POLLING_INTERVAL_SECONDS),
742+
interval: Duration(seconds: EnvironmentConfig.USER_REPOSITORY_POLLING_INTERVAL_SECONDS),
743743
),
744744
PollingRegistration(
745745
listener: context.read<SystemInfoRepository>(),
746-
interval: const Duration(seconds: EnvironmentConfig.SYSTEM_INFO_REPOSITORY_POLLING_INTERVAL_SECONDS),
746+
interval: Duration(seconds: EnvironmentConfig.SYSTEM_INFO_REPOSITORY_POLLING_INTERVAL_SECONDS),
747747
),
748748
if (supportsExtensions)
749749
PollingRegistration(
750750
listener: context.read<ExternalContactsRepository>(),
751-
interval: const Duration(seconds: EnvironmentConfig.EXTERNAL_CONTACTS_REPOSITORY_POLLING_INTERVAL_SECONDS),
751+
interval: Duration(seconds: EnvironmentConfig.EXTERNAL_CONTACTS_REPOSITORY_POLLING_INTERVAL_SECONDS),
752752
),
753753
if (isVoicemailsEnabled)
754754
PollingRegistration(
755755
listener: context.read<VoicemailRepository>(),
756-
interval: const Duration(seconds: EnvironmentConfig.VOICEMAIL_REPOSITORY_POLLING_INTERVAL_SECONDS),
756+
interval: Duration(seconds: EnvironmentConfig.VOICEMAIL_REPOSITORY_POLLING_INTERVAL_SECONDS),
757757
),
758758
if (cliSettingsRepository is CallerIdSettingsRepositoryRemoteImpl)
759759
PollingRegistration(
760760
listener: cliSettingsRepository,
761-
interval: const Duration(seconds: EnvironmentConfig.CALLER_ID_SETTINGS_REPOSITORY_POLLING_INTERVAL_SECONDS),
761+
interval: Duration(seconds: EnvironmentConfig.CALLER_ID_SETTINGS_REPOSITORY_POLLING_INTERVAL_SECONDS),
762762
),
763763
if (favoritesRepository is FavoritesRepositorySyncableImpl)
764764
PollingRegistration(
765765
listener: favoritesRepository,
766-
interval: const Duration(seconds: EnvironmentConfig.FAVORITES_REPOSITORY_POLLING_INTERVAL_SECONDS),
766+
interval: Duration(seconds: EnvironmentConfig.FAVORITES_REPOSITORY_POLLING_INTERVAL_SECONDS),
767767
),
768768
if (sipSubscriptionsRepository is SipSubscriptionsRepositorySyncableImpl)
769769
PollingRegistration(
770770
listener: sipSubscriptionsRepository,
771-
interval: const Duration(seconds: EnvironmentConfig.SIP_SUBSCRIPTIONS_REPOSITORY_POLLING_INTERVAL_SECONDS),
771+
interval: Duration(seconds: EnvironmentConfig.SIP_SUBSCRIPTIONS_REPOSITORY_POLLING_INTERVAL_SECONDS),
772772
),
773773
];
774774
}

lib/common/logging/logzio_logging_service.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class LogzioLoggingService implements RemoteLoggingService {
1515
static LogzioLoggingService? fromEnvironment(bool enabled) {
1616
if (!enabled) return null;
1717

18-
const url = EnvironmentConfig.REMOTE_LOGZIO_LOGGING_URL;
19-
const token = EnvironmentConfig.REMOTE_LOGZIO_LOGGING_TOKEN;
18+
final url = EnvironmentConfig.REMOTE_LOGZIO_LOGGING_URL;
19+
final token = EnvironmentConfig.REMOTE_LOGZIO_LOGGING_TOKEN;
2020
if (url == null || token == null) return null;
2121

2222
final minLevel = Level.LEVELS.firstWhere((l) => l.name == EnvironmentConfig.REMOTE_LOGZIO_LOG_LEVEL);

lib/data/feature_access.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ abstract final class CallMapper {
402402
isBlindTransferEnabled: transferConfig.enableBlindTransfer,
403403
isAttendedTransferEnabled: transferConfig.enableAttendedTransfer,
404404
),
405-
triggerConfig: const CallTriggerConfig(
405+
triggerConfig: CallTriggerConfig(
406406
smsFallback: SmsFallbackTriggerConfig(
407407
enabled: EnvironmentConfig.CALL_TRIGGER_MECHANISM_SMS,
408408
available: EnvironmentConfig.CALL_TRIGGER_MECHANISM_SMS,

lib/environment_config.dart

Lines changed: 118 additions & 47 deletions
Large diffs are not rendered by default.

lib/features/autoprovision/view/autoprovision_screen_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class AutoprovisionScreenPage extends StatelessWidget {
3434
final tenantId = this.tenantId ?? '';
3535
final oldTenant = context.read<AppBloc>().state.session.tenantId;
3636

37-
const defaultCoreUrl = EnvironmentConfig.CORE_URL ?? EnvironmentConfig.DEMO_CORE_URL;
37+
final defaultCoreUrl = EnvironmentConfig.CORE_URL ?? EnvironmentConfig.DEMO_CORE_URL;
3838
final coreUrl = this.coreUrl;
3939
final oldCoreUrl = context.read<AppBloc>().state.session.coreUrl;
4040

41-
const coreVersionConstraint = EnvironmentConfig.CORE_VERSION_CONSTRAINT;
41+
final coreVersionConstraint = EnvironmentConfig.CORE_VERSION_CONSTRAINT;
4242
final config = AutoprovisionConfig(
4343
configToken: configToken,
4444
oldToken: oldToken,

lib/features/cdrs/features/number_cdrs_log/view/number_cdrs_screen_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class NumberCdrsScreenPage extends StatelessWidget {
2323
return BlocProvider(
2424
create: (context) =>
2525
NumberCdrsLogCubit(number, context.read<CdrsLocalRepository>(), context.read<CdrsRemoteRepository>())..init(),
26-
child: NumberCdrsScreen(title: const Text(EnvironmentConfig.APP_NAME), videoVisible: videoVisible),
26+
child: NumberCdrsScreen(title: Text(EnvironmentConfig.APP_NAME), videoVisible: videoVisible),
2727
);
2828
}
2929
}

lib/features/cdrs/view/recent_cdrs_screen_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class RecentCdrsScreenPage extends StatelessWidget {
2929
),
3030
],
3131
child: RecentCdrsScreen(
32-
title: const Text(EnvironmentConfig.APP_NAME),
32+
title: Text(EnvironmentConfig.APP_NAME),
3333
transferEnabled: featureAccess.callConfig.capabilities.isBlindTransferEnabled,
3434
videoEnabled: featureAccess.callConfig.capabilities.isVideoCallEnabled,
3535
chatsEnabled: featureAccess.messagingConfig.chatsPresent,

lib/features/contacts/view/contacts_screen_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ContactsScreenPage extends StatelessWidget {
2626
@override
2727
Widget build(BuildContext context) {
2828
final widget = ContactsScreen(
29-
title: const Text(EnvironmentConfig.APP_NAME),
29+
title: Text(EnvironmentConfig.APP_NAME),
3030
sourceTypes: sourceTypes,
3131
sourceTypeWidgetBuilder: _contactSourceTypeWidgetBuilder,
3232
);

lib/features/favorites/view/favorites_screen_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FavoritesScreenPage extends StatelessWidget {
2121
final cdrsEnabled = featureAccess.bottomMenuConfig.getTabEnabled<RecentsBottomMenuTab>()?.supportsCallHistory;
2222

2323
final widget = FavoritesScreen(
24-
title: const Text(EnvironmentConfig.APP_NAME),
24+
title: Text(EnvironmentConfig.APP_NAME),
2525
transferEnabled: featureAccess.callConfig.capabilities.isBlindTransferEnabled,
2626
videoEnabled: featureAccess.callConfig.capabilities.isVideoCallEnabled,
2727
chatsEnabled: featureAccess.messagingConfig.chatsPresent,

lib/features/keypad/view/keypad_screen_page.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class KeypadScreenPage extends StatelessWidget {
1818
final featureAccess = context.read<FeatureAccess>();
1919

2020
final widget = KeypadScreen(
21-
title: const Text(EnvironmentConfig.APP_NAME),
21+
title: Text(EnvironmentConfig.APP_NAME),
2222
videoEnabled: featureAccess.callConfig.capabilities.isVideoCallEnabled,
2323
transferEnabled: featureAccess.callConfig.capabilities.isBlindTransferEnabled,
2424
);

0 commit comments

Comments
 (0)