sharedPrefs function

Future<SharedPrefsResult> sharedPrefs(
  1. SharedPrefsInput input
)

Reads, writes, and clears SharedPreferences via the ext.fdb.sharedPrefs VM service extension registered by fdb_helper.

Never throws; all error conditions are represented as sealed result cases.

Implementation

Future<SharedPrefsResult> sharedPrefs(SharedPrefsInput input) async {
  try {
    final isolateId = await checkFdbHelper();
    if (isolateId == null) return const PrefsNoFdbHelper();

    return switch (input) {
      PrefsGetInput(:final key) => await _get(isolateId, key),
      PrefsGetAllInput() => await _getAll(isolateId),
      PrefsSetInput(:final key, :final value, :final type) => await _set(isolateId, key, value, type),
      PrefsRemoveInput(:final key) => await _remove(isolateId, key),
      PrefsClearInput() => await _clear(isolateId),
    };
  } on AppDiedException catch (e) {
    return PrefsAppDied(logLines: e.logLines, reason: e.reason);
  } catch (e) {
    return PrefsError(e.toString());
  }
}