Skip to content

Commit

Permalink
Fix compatibility with lower versions
Browse files Browse the repository at this point in the history
  • Loading branch information
gdelataillade committed Sep 20, 2024
1 parent 20fa088 commit 58fa3b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ SPEC CHECKSUMS:
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe

PODFILE CHECKSUM: 8af8e7ee73303366e8affe0fe6e44bcbddffaa5b
PODFILE CHECKSUM: e7940f0b797939de6f46d152874d3c9091c48dd2

COCOAPODS: 1.15.2
4 changes: 2 additions & 2 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ packages:
dependency: transitive
description:
name: permission_handler_platform_interface
sha256: fe0ffe274d665be8e34f9c59705441a7d248edebbe5d9e3ec2665f88b79358ea
sha256: e9c8eadee926c4532d0305dff94b85bf961f16759c3af791486613152af4b4f9
url: "https://pub.dev"
source: hosted
version: "4.2.2"
version: "4.2.3"
permission_handler_windows:
dependency: transitive
description:
Expand Down
35 changes: 21 additions & 14 deletions lib/model/alarm_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,39 @@ class AlarmSettings {

/// Constructs an `AlarmSettings` instance from the given JSON data.
factory AlarmSettings.fromJson(Map<String, dynamic> json) {
// Add support from earlier versions of the plugin.
final notificationTitle = json['notificationTitle'] as String?;
final notificationBody = json['notificationBody'] as String?;
NotificationSettings notificationSettings;

var notificationSettings = NotificationSettings.fromJson(
json['notificationSettings'] as Map<String, dynamic>,
);
// Ensure compatibility with plugin versions below 4.0.0.
if (json.containsKey('notificationSettings') &&
json['notificationSettings'] != null) {
notificationSettings = NotificationSettings.fromJson(
json['notificationSettings'] as Map<String, dynamic>,
);
} else {
final notificationTitle = json['notificationTitle'] as String? ?? '';
final notificationBody = json['notificationBody'] as String? ?? '';

if (notificationTitle != null || notificationBody != null) {
notificationSettings = notificationSettings.copyWith(
title: notificationTitle ?? notificationSettings.title,
body: notificationBody ?? notificationSettings.body,
notificationSettings = NotificationSettings(
title: notificationTitle,
body: notificationBody,
);
}

final warningNotificationOnKill =
json.containsKey('warningNotificationOnKill')
? json['warningNotificationOnKill'] as bool
: json['enableNotificationOnKill'] as bool? ?? true;

return AlarmSettings(
id: json['id'] as int,
dateTime: DateTime.fromMicrosecondsSinceEpoch(json['dateTime'] as int),
assetAudioPath: json['assetAudioPath'] as String,
notificationSettings: notificationSettings,
loopAudio: json['loopAudio'] as bool,
loopAudio: json['loopAudio'] as bool? ?? true,
vibrate: json['vibrate'] as bool? ?? true,
volume: json['volume'] as double?,
fadeDuration: json['fadeDuration'] as double,
warningNotificationOnKill:
json['warningNotificationOnKill'] as bool? ?? true,
fadeDuration: json['fadeDuration'] as double? ?? 0.0,
warningNotificationOnKill: warningNotificationOnKill,
androidFullScreenIntent: json['androidFullScreenIntent'] as bool? ?? true,
);
}
Expand Down

0 comments on commit 58fa3b6

Please sign in to comment.