configValueSource function

RemoteConfigValueSource configValueSource(
  1. String key, {
  2. String? app,
})

Where key's current value came from.

A caller that cannot tell a default from a fetched value cannot tell whether a fetch has taken effect.

Implementation

RemoteConfigValueSource configValueSource(String key, {String? app}) {
  final k = key.toNativeUtf8();
  try {
    final rc = _onApp(app, (a) => fdbRcValueSource(a, k.cast()));
    if (rc < 0) {
      throw StateError(
        rc == -1
            ? 'Remote Config is not initialized${_on(app)}'
            : 'a key is required',
      );
    }
    // Mapped by name, not by index. The SDK orders these static, remote,
    // default; this enum orders them static, default, remote. Casting through
    // the index would swap the two that matter.
    return switch (rc) {
      0 => RemoteConfigValueSource.static,
      1 => RemoteConfigValueSource.remote,
      2 => RemoteConfigValueSource.defaultValue,
      _ => RemoteConfigValueSource.static,
    };
  } finally {
    calloc.free(k);
  }
}