gdelataillade / alarm

A Flutter plugin to easily manage alarms on iOS and Android
https://pub.dev/packages/alarm
MIT License
132 stars 86 forks source link

Alarm_settings.dart fromJson bug #74

Closed whowillcare closed 1 year ago

whowillcare commented 1 year ago

Alarm plugin version 1.2.0 probabaly ealier version has the same issue

Describe the bug

/// Constructs an `AlarmSettings` instance from the given JSON data.
  factory AlarmSettings.fromJson(Map<String, dynamic> json) => AlarmSettings(
        id: json['id'] as int,
        dateTime: DateTime.fromMicrosecondsSinceEpoch(json['dateTime'] as int),
        assetAudioPath: json['assetAudioPath'] as String,
        loopAudio: json['loopAudio'] as bool,
        vibrate: json['vibrate'] as bool,
        volumeMax: json['volumeMax'] as bool,
        fadeDuration: json['fadeDuration'] as double,
        notificationTitle: json['notificationTitle'] as String?,
        notificationBody: json['notificationBody'] as String?,
        enableNotificationOnKill: json['enableNotificationOnKill'] as bool,
        stopOnNotificationOpen: json['stopOnNotificationOpen'] as bool,
      );

it makes it's not compatible with previous version, say the newly added 'volumeMax' key. and fromJson will throw exception when it's decoding old saved alarm.

To Reproduce

  1. old app with alarm set with old alarm module
  2. upgrade to 1.2.0 and then compile and run app again, if there is no try and catch, app will throw exception when Alarm.init is called.
gdelataillade commented 1 year ago

Hi @whowillcare,

Thank you for opening the issue. I just fix the bug and published a new version: 1.2.1.

Let me know if you have any problem.

russellmo commented 1 year ago

@gdelataillade Same issue, old app with alarm set with old alarm module 1.2.2 -> 2.1.0

type 'Null' is not a subtype of type 'bool' in type cast.

androidFullScreenIntent: json['androidFullScreenIntent'] as bool,

gdelataillade commented 1 year ago

Sorry about that, I'll try to fix it soon.

In the meantime, you can avoid the issue in your project by rescheduling manually your existing alarms.

gdelataillade commented 1 year ago

Should be fixed in 2.1.1.

Please reopen issue if you still have the issue.