PIbd-32_Stroev_V_M_PMD/lib/components/utils/debounce.dart

20 lines
362 B
Dart
Raw Normal View History

2024-10-30 22:39:56 +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, {
Duration delay = const Duration(milliseconds: 500),
}) {
_timer?.cancel();
_timer = Timer(delay, action);
}
}