stream static method

Stream<DateTime> stream({
  1. Duration interval = const Duration(seconds: 1),
  2. bool isUtc = false,
  3. NtpServer server = NtpServer.google,
  4. String? customServer,
  5. int port = 123,
  6. int timeout = 5,
})

Emits a continuous stream of accurate DateTime values at interval.

Ideal for live clocks, auction timers, and TOTP countdowns. Automatically triggers background resynchronization if the cache expires or if system clock tampering is detected.

Implementation

static Stream<DateTime> stream({
  Duration interval = const Duration(seconds: 1),
  bool isUtc = false,
  NtpServer server = NtpServer.google,
  String? customServer,
  int port = 123,
  int timeout = 5,
}) async* {
  yield await now(
    isUtc: isUtc,
    server: server,
    customServer: customServer,
    port: port,
    timeout: timeout,
  );

  yield* Stream.periodic(interval, (_) {
    return nowSync(
      isUtc: isUtc,
      server: server,
      customServer: customServer,
      port: port,
      timeout: timeout,
    );
  });
}