Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,19 @@ class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier {
}

/// Sets the default parameter values for the current instance.
/// Only booleans, strings and numbers are supported as values of the map
Future<void> setDefaults(Map<String, dynamic> defaultParameters) {
defaultParameters.forEach(_checkIsSupportedType);
return _delegate.setDefaults(defaultParameters);
}

void _checkIsSupportedType(String key, dynamic value) {
if (value is! bool && value is! num && value is! String) {
throw ArgumentError(
'Invalid value type "${value.runtimeType}" for key "$key". '
'Only booleans, numbers and strings are supported as config values. '
"If you're trying to pass a json object – convert it to string beforehand",
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ void main() {
remoteConfig.setDefaults(mockParameters);
verify(mockRemoteConfigPlatform.setDefaults(mockDefaultParameters));
});

test('should throw when non-primitive value is passed', () {
expect(
() => remoteConfig.setDefaults({
'key': {'nested': 'object'}
}),
throwsArgumentError,
);
});
});
});
}
Expand Down