Flutter:有什么办法可以在指定的时间启动秒表类吗?

时间:2019-05-21 16:45:22

标签: flutter

我一直希望下面这样,但是显然这行不通。

  Stopwatch watch = new Stopwatch();
    watch.elapsed = watch.elapsed + Duration(hours: 01, minutes: 23, seconds: 31);

有什么方法可以达到预期的结果吗?

-感谢您提供任何提示/线索。

1 个答案:

答案 0 :(得分:1)

Stopwatch用于测量间隔-通常在性能测试中使用。也许您想要一个Timer。或子类秒表。

  Timer t = Timer(Duration(hours: 01, minutes: 23, seconds: 31), () {
    print('time to take the cake out of the oven');
  });
  ...
  t.cancel(); // use this if you want to cancel the timer early


class OffsetStopwatch extends Stopwatch {
  Duration offset;

  OffsetStopwatch(this.offset);

  Duration get offsetElapsed => offset + elapsed;
}