2024-12-03 23:24:47 +04:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
class Debounce {
|
|
|
|
factory Debounce() => _instance;
|
|
|
|
|
|
|
|
Debounce._();
|
|
|
|
|
|
|
|
static final Debounce _instance = Debounce._();
|
|
|
|
|
|
|
|
static Timer? _timer;
|
|
|
|
|
|
|
|
static void run (
|
|
|
|
VoidCallback action, {
|
2024-12-04 01:02:56 +04:00
|
|
|
Duration delay = const Duration(milliseconds: 5000),
|
2024-12-03 23:24:47 +04:00
|
|
|
}) {
|
|
|
|
_timer?.cancel();
|
|
|
|
_timer = Timer(delay, action);
|
|
|
|
}
|
|
|
|
}
|