workerKeys function Controllers Providers

  1. @Riverpod(keepAlive: true)
WorkerKeysState workerKeys(
  1. Ref<Object?> ref
)

Provider and controller of List<WorkerKey>.

Add, delete, save and load WorkerKeys. (They are saved in SharedPreferences)

Implementation

@Riverpod(keepAlive: true)
WorkerKeysState workerKeys(Ref ref) {
  final json = jsonDecode(
    locator<SharedPreferences>().getString(workerKeysInSharedPref) ?? '[]',
  );
  var keys = <WorkerKey>[];
  if (json is List) {
    keys = json
        .whereType<Map<String, dynamic>>()
        .map<WorkerKey>(WorkerKey.fromJson)
        .toList(growable: false);
  }
  return WorkerKeysState(ref: ref, keys: keys);
}