usePeriodicTimer method

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

Retrieves or creates a periodic Timer.

key: A unique string key to identify the periodic Timer. callback: The function to execute on each timer tick. duration: The interval between timer ticks.

Returns a Timer that fires periodically, associated with the given key.

Implementation

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