periodicTimer function Null safety

TimedGenerator periodicTimer(
  1. Duration interval,
  2. {Duration alignment = Duration.zero}
)

Implementation

TimedGenerator periodicTimer(
  Duration interval, {
  Duration alignment = Duration.zero,
}) {
  assert(interval > Duration.zero);

  DateTime? next;

  return (DateTime now) {
    next = alignDateTime((next ?? now).add(interval), alignment);
    if (now.compareTo(next!) < 0) {
      next = alignDateTime(now.add(interval), alignment);
    }
    return next;
  };
}