2024-12-18 03:01:46 +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-12-18 13:10:57 +04:00
|
|
|
VoidCallback action, {
|
|
|
|
Duration delay = const Duration(milliseconds: 1000),
|
|
|
|
}) {
|
2024-12-18 03:01:46 +04:00
|
|
|
_timer?.cancel();
|
|
|
|
_timer = Timer(delay, action);
|
|
|
|
}
|
2024-12-18 13:10:57 +04:00
|
|
|
}
|