RecurrentScheduledTrigger class Null safety

A trigger that resume/pause sampling based on a recurrent scheduled date and time. Stops / pause after the specified duration.

Supports daily, weekly and monthly recurrences. Yearly recurrence is not supported, since data sampling is not intended to run on such long time scales.

Here are a couple of examples:

 // collect every day at 13:30
 RecurrentScheduledTrigger(type: RecurrentType.daily, time: Time(hour: 13, minute: 30));

 // collect every other day at 13:30
 RecurrentScheduledTrigger(type: RecurrentType.daily, separationCount: 1, time: Time(hour: 13, minute: 30));

 // collect every wednesday at 12:23
 RecurrentScheduledTrigger(type: RecurrentType.weekly, dayOfWeek: DateTime.wednesday, time: Time(hour: 12, minute: 23));

 // collect every 2nd monday at 12:23
 RecurrentScheduledTrigger(type: RecurrentType.weekly, dayOfWeek: DateTime.monday, separationCount: 1, time: Time(hour: 12, minute: 23));

 // collect monthly in the second week on a monday at 14:30
 RecurrentScheduledTrigger(type: RecurrentType.monthly, weekOfMonth: 2, dayOfWeek: DateTime.monday, time: Time(hour: 14, minute: 30));

 // collect quarterly on the 11th day of the first month in each quarter at 21:30
 RecurrentScheduledTrigger(type: RecurrentType.monthly, dayOfMonth: 11, separationCount: 2, time: Time(hour: 21, minute: 30));

Recurrent scheduled triggers can be saved across app shutdown by setting remember to true. For example;

      RecurrentScheduledTrigger(
        triggerId: '1234wef',
        type: RecurrentType.monthly,
        dayOfMonth: 11,
        separationCount: 2,
        time: Time(hour: 21, minute: 30),
        remember: true,
      );

would create the quarterly schedule above. But if the app shuts down before this schedule, and restarted after, the trigger would still trigger (immediately). Note that the triggerId must be specified when remembering triggers (it is used as the key).

Thanks to Shantanu Kher for inspiration in his blog post on Again and Again! Managing Recurring Events In a Data Model. We are, however, not using yearly recurrence. Moreover, monthly recurrences make little sense in mobile sensing, even though it is supported.

Inheritance
Annotations

Constructors

RecurrentScheduledTrigger({required RecurrentType type, required Time time, DateTime? end, int separationCount = 0, int? maxNumberOfSampling, int? dayOfWeek, int? weekOfMonth, int? dayOfMonth, bool remember = false, String? triggerId, Duration duration = const Duration(seconds: 10)})
Creates a RecurrentScheduledTrigger.
RecurrentScheduledTrigger.fromJson(Map<String, dynamic> json)
factory

Properties

$type String?
The runtime class name (type) of this object. Used for deserialization from JSON objects.
read / write, inherited
dayOfMonth int?
If monthly recurrence, specify the day of the month. [...]
read / write
dayOfWeek int?
If weekly recurrence, specify which day of week. [...]
read / write
duration Duration
The duration (until paused) of the the sampling.
read / write, inherited
end DateTime?
End time and date. If null, this trigger keeps sampling forever.
read / write
firstOccurrence DateTime
The date and time of the first occurrence of this trigger.
read-only
fromJsonFunction Function
The function which can convert a JSON string to an object of this type.
read-only, override
hashCode int
The hash code for this object. [...]
read-only, inherited
jsonType String
Return the $type to be used for JSON serialization of this class. Default is runtimeType. Only specify this if you need another type.
read-only, inherited
maxNumberOfSampling int?
Maximum number of samplings. [...]
read / write
period Duration
The period between the recurring samplings.
read / write, inherited-setter, override-getter
remember bool
Should this recurrent scheduled trigger be remembered across app restart? [...]
read / write
requiresMasterDevice bool?
Determines whether the trigger needs to be evaluated on a master device (MasterDeviceDescriptor). For example, this is the case when the trigger is time bound and needs to be evaluated by a task scheduler running on a master device.
@JsonKey(ignore: true), read / write, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
separationCount int
Separation between recurrences. [...]
read / write
sourceDeviceRoleName String?
The device role name from which the trigger originates.
read / write, inherited
time Time
The time of day of this trigger.
read / write
triggerId String?
The unique id of this trigger. Only used if remember is true.
read / write
type RecurrentType
The type of recurrence - daily, weekly or monthly.
read / write
weekOfMonth int?
If monthly recurrence, specify the week in the month. [...]
read / write

Methods

nextMonthlyDay(DateTime fromDate) DateTime
The next day in a monthly occurrence from the given fromDate.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toJson() Map<String, dynamic>
Return a JSON encoding of this object.
override
toString() String
A string representation of this object. [...]
override

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited

Constants

daysPerMonth → const int
30
daysPerWeek → const int
7