getSavedAlarms static method

Future<List<AlarmSettings>> getSavedAlarms()

Returns all alarms info from local storage in the case app is terminated and we need to restore previously scheduled alarms.

Implementation

static Future<List<AlarmSettings>> getSavedAlarms() async {
  await _waitUntilInitialized();

  final alarms = <AlarmSettings>[];
  final keys = _prefs.getKeys();

  for (final key in keys) {
    if (key.startsWith(prefix)) {
      final res = _prefs.getString(key);
      alarms.add(
        AlarmSettings.fromJson(json.decode(res!) as Map<String, dynamic>),
      );
    }
  }

  return alarms;
}