addAlarm method
Implementation
void addAlarm(AlarmModel alarm, {int? position}) {
// there can only be one mandatory alarm
// this allows the user to override the alarm wordage with their own
if (alarm.type == AlarmType.mandatory &&
(_alarms.firstWhereOrNull((a) => a.type == AlarmType.mandatory) !=
null)) return;
// there can only be one validation alarm
// this allows the user to override the alarm wordage with their own
if (alarm.type == AlarmType.validation &&
(_alarms.firstWhereOrNull((a) => a.type == AlarmType.validation) !=
null)) return;
// add the alarm
if (!_alarms.contains(alarm)) {
if (position != null) {
if (position < 0) position = 0;
if (position > _alarms.length) position = _alarms.length;
_alarms.insert(position, alarm);
} else {
_alarms.add(alarm);
}
// register a listener to the alarm
alarm.onChange(_onAlarmChange);
// add alarm to children
children ??= [];
if (!children!.contains(alarm)) children!.add(alarm);
// set alarming value
// this seems to be necessary in release mode
alarming = (getActiveAlarm() != null);
}
}