run method

void run(
  1. VoidCallback action
)

Runs the provided action after a delay defined by delay.

If this method is called while a previous timer is active, it cancels the previous timer and starts a new one, effectively resetting the delay period.

  • action: The callback function to be executed after the delay.

Implementation

void run(VoidCallback action) {
  _action = action;
  _timer?.cancel();
  if (delay != null) {
    _timer = Timer(delay!, () {
      // Check if the action is not null before executing it.
      if (_action != null) {
        _action!();
      }
    });
  }
}