useTimer method

Timer useTimer({
  1. required String key,
  2. required void callback(),
  3. required Duration duration,
})

Retrieves or creates a one-time Timer.

key: A unique string key to identify the Timer. callback: The function to execute when the timer fires. duration: The duration after which to fire the timer.

Returns a Timer associated with the given key.

Implementation

Timer useTimer({
  required String key,
  required void Function() callback,
  required Duration duration,
}) {
  return _getOrCreate(
      key: key,
      create: () => Timer(duration, callback),
      disposeHandler: (timer) async => timer.cancel());
}