17 lines
339 B
Dart
17 lines
339 B
Dart
|
import 'dart:async';
|
||
|
import 'dart:ui';
|
||
|
|
||
|
class Debouce {
|
||
|
factory Debouce() => _instance;
|
||
|
|
||
|
Debouce._();
|
||
|
|
||
|
static final Debouce _instance = Debouce._();
|
||
|
|
||
|
static Timer? _timer;
|
||
|
|
||
|
static void run(VoidCallback action, {Duration delay = const Duration(milliseconds: 500),}) {
|
||
|
_timer?.cancel();
|
||
|
_timer = Timer(delay, action);
|
||
|
}
|
||
|
}
|