Skip to content

Commit

Permalink
Feature/prevents int type error (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raonshi authored Feb 2, 2024
1 parent 5baed7a commit b4c3e7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 11 additions & 6 deletions example/lib/screens/edit_alarm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ class _ExampleAlarmEditScreenState extends State<ExampleAlarmEditScreen> {
setState(() {
final DateTime now = DateTime.now();
selectedDateTime = now.copyWith(
hour: res.hour,
minute: res.minute,
second: 0,
millisecond: 0,
microsecond: 0
);
hour: res.hour,
minute: res.minute,
second: 0,
millisecond: 0,
microsecond: 0);
if (selectedDateTime.isBefore(now)) {
selectedDateTime = selectedDateTime.add(const Duration(days: 1));
}
Expand All @@ -83,10 +82,16 @@ class _ExampleAlarmEditScreenState extends State<ExampleAlarmEditScreen> {
}

AlarmSettings buildAlarmSettings() {
//[DO] id must be less than Android's max int value
final id = creating
? DateTime.now().millisecondsSinceEpoch % 10000
: widget.alarmSettings!.id;

// [DON'T] id must be less than Android's max int value
// final id = creating
// ? DateTime.now().millisecondsSinceEpoch
// : widget.alarmSettings!.id;

final alarmSettings = AlarmSettings(
id: id,
dateTime: selectedDateTime,
Expand Down
4 changes: 3 additions & 1 deletion lib/model/alarm_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class AlarmSettings {
required this.notificationBody,
this.enableNotificationOnKill = true,
this.androidFullScreenIntent = true,
});
}) : assert(id != 0 && id != -1, "id cannot be set to 0 or -1"),
assert(id <= 2147483647,
"id cannot be set larger then Android Int.MAX_VALUE");

/// Constructs an `AlarmSettings` instance from the given JSON data.
factory AlarmSettings.fromJson(Map<String, dynamic> json) => AlarmSettings(
Expand Down

0 comments on commit b4c3e7c

Please sign in to comment.