workerKeys function Controllers Providers
- @Riverpod(keepAlive: true)
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);
}