buildValidatedRemoteConfigDefaults function
Merges DreamIC's AppConfigBase.defaultRemoteConfig with the
consumer-supplied additionalDefaultConfigs and validates that every
value in the merged map is a bool, num, or String — the only types
Firebase Remote Config setDefaults accepts.
Throws an ArgumentError (matching Firebase's own setDefaults guard,
which throws ArgumentError on null) naming each offending
'key' = RuntimeType if any value is unsupported. This guard runs on
every init path (live, mock, emulator) so a bad consumer default surfaces
in local development rather than first crashing app startup on the live
Remote Config path.
Exposed via @visibleForTesting (mirroring the @visibleForTesting
setters in AppConfigBase) so validator tests can call it directly
without a Firebase-init/GetIt harness.
Implementation
@visibleForTesting
Map<String, dynamic> buildValidatedRemoteConfigDefaults(
Map<String, dynamic>? additionalDefaultConfigs,
) {
final merged = <String, dynamic>{
...AppConfigBase.defaultRemoteConfig,
...?additionalDefaultConfigs,
};
final offenders = <String>[];
merged.forEach((key, value) {
if (value is! bool && value is! num && value is! String) {
offenders.add("'$key' = ${value.runtimeType}");
}
});
if (offenders.isNotEmpty) {
throw ArgumentError(
'Invalid Remote Config default value(s): ${offenders.join(', ')}. '
'Firebase Remote Config defaults must be bool, num, or String. '
'An unsupported value would otherwise crash app startup on the live '
'Remote Config path (FirebaseRemoteConfig.setDefaults rejects it).',
);
}
return merged;
}