2024-09-22 20:35:55 +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(
|
2024-09-25 12:55:28 +04:00
|
|
|
VoidCallback action, {
|
|
|
|
Duration delay = const Duration(milliseconds: 500),
|
|
|
|
}) {
|
2024-09-22 20:35:55 +04:00
|
|
|
_timer?.cancel();
|
|
|
|
_timer = Timer(delay, action);
|
|
|
|
}
|
2024-09-25 12:55:28 +04:00
|
|
|
}
|