2024-10-16 11:29:51 +04:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
class Debounce {
|
|
|
|
factory Debounce() => _instance;
|
|
|
|
|
|
|
|
Debounce._();
|
|
|
|
|
|
|
|
static final Debounce _instance = Debounce._();
|
|
|
|
|
|
|
|
static Timer? _timer;
|
|
|
|
|
2024-10-16 23:18:15 +04:00
|
|
|
static void run(
|
|
|
|
VoidCallback action, {
|
|
|
|
Duration delay = const Duration(milliseconds: 500),
|
2024-10-16 11:29:51 +04:00
|
|
|
}) {
|
|
|
|
_timer?.cancel();
|
|
|
|
_timer = Timer(delay, action);
|
|
|
|
}
|
2024-10-16 23:18:15 +04:00
|
|
|
}
|