Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:async
  3. Timer
  4. Timer.new factory constructor
Timer.new
description

Timer constructor

Timer(
  1. Durationduration,
  2. voidcallback()
)

Creates a new timer.

Thecallback function is invoked after the givenduration.

Example:

final timer =    Timer(const Duration(seconds: 5), () => print('Timer finished'));// Outputs after 5 seconds: "Timer finished".

Implementation

factory Timer(Duration duration, void Function() callback) {  if (Zone.current == Zone.root) {    // No need to bind the callback. We know that the root's timer will    // be invoked in the root zone.    return Zone.current.createTimer(duration, callback);  }  return Zone.current.createTimer(    duration,    Zone.current.bindCallbackGuarded(callback),  );}
  1. Dart
  2. dart:async
  3. Timer
  4. Timer.new factory constructor
Timer class

[8]ページ先頭

©2009-2025 Movatter.jp