addRule method
Implementation
void addRule(DVAlertRule rule) {
if (rule.forDuration <= Duration.zero) {
throw ArgumentError.value(rule.forDuration, 'forDuration',
'a rule that fires on a single sample fires on a pause; give it a '
'positive duration');
}
final Duration? resolveAfter = rule.resolveAfter;
if (resolveAfter != null && resolveAfter < Duration.zero) {
throw ArgumentError.value(resolveAfter, 'resolveAfter', 'is negative');
}
final Object threshold = rule.condition.threshold;
if (rule.signal.measuresDuration ? threshold is! Duration : threshold is! num) {
throw ArgumentError.value(
threshold,
'condition',
rule.signal.measuresDuration
? '${rule.signal} is a duration; give the threshold as a Duration'
: '${rule.signal} is a number; give the threshold as a number',
);
}
if (_rules.containsKey(rule.name)) {
throw ArgumentError.value(
rule.name, 'name', 'a rule with this name is already declared');
}
_rules[rule.name] = _RuleState(rule);
if (rule.notify.isEmpty) {
_diagnose('DV-ALERT-005',
'rule ${rule.name} has no target; when it fires nobody hears');
}
}