Skip to content

Commit

Permalink
Fix range schedule not working
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanSarwar45 committed Jun 24, 2024
1 parent f39cbf1 commit 115a689
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/alarm/data/alarm_settings_schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ SettingGroup alarmSettingsSchema = SettingGroup(
DateTimeSetting(
"Date Range",
(context) => AppLocalizations.of(context)!.alarmRangeSetting,
[],
[DateTime.now(), DateTime.now().add(const Duration(days: 2))],
rangeOnly: true,
enableConditions: [
ValueCondition(["Type"], (value) => value == RangeAlarmSchedule)
Expand Down
16 changes: 9 additions & 7 deletions lib/alarm/types/schedules/range_alarm_schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RangeAlarmSchedule extends AlarmSchedule {
late final AlarmRunner _alarmRunner;
late final DateTimeSetting _datesRangeSetting;
late final SelectSetting<RangeInterval> _intervalSetting;
bool _isFinished = true;
bool _isFinished = false;

RangeInterval get interval => _intervalSetting.value;
DateTime get startDate => _datesRangeSetting.value.first;
Expand Down Expand Up @@ -42,21 +42,23 @@ class RangeAlarmSchedule extends AlarmSchedule {
}

@override
Future<void> schedule(Time time,String description) async {
Future<void> schedule(Time time, String description) async {
// All the dates are not scheduled at once
// Instead we schedule the next date after the current one is finished

DateTime alarmDate = getDailyAlarmDate(time, scheduledDate: startDate);
if (alarmDate.day <= endDate.day) {
await _alarmRunner.schedule(alarmDate,description);
_isFinished = false;
} else {
print('$alarmDate $startDate $endDate');
if (alarmDate.isAfter(endDate)) {
_isFinished = true;
} else {
print("_____________");
await _alarmRunner.schedule(alarmDate, description);
_isFinished = false;
}
}

@override
Future<void> cancel()async {
Future<void> cancel() async {
await _alarmRunner.cancel();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/common/widgets/fields/date_picker_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import 'package:intl/intl.dart';

class DatePickerField<T> extends StatefulWidget {
const DatePickerField({
Key? key,
super.key,
required this.title,
this.description,
required this.onChanged,
required this.value,
this.rangeOnly = false,
}) : super(key: key);
});

final List<DateTime> value;
final String title;
Expand Down

0 comments on commit 115a689

Please sign in to comment.