mirror of
https://github.com/Livinglist/Hacki.git
synced 2025-08-14 01:58:29 +08:00
20 lines
315 B
Dart
20 lines
315 B
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
class Debouncer {
|
|
Debouncer({
|
|
required this.delay,
|
|
});
|
|
|
|
final Duration delay;
|
|
Timer? _timer;
|
|
|
|
Timer run(VoidCallback action) {
|
|
_timer?.cancel();
|
|
return _timer = Timer(delay, action);
|
|
}
|
|
|
|
void dispose() => _timer?.cancel();
|
|
}
|