mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-10 16:00:28 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
20
lib/util/throttler.dart
Normal file
20
lib/util/throttler.dart
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class Throttler {
|
||||
final Duration duration;
|
||||
int? lastActionTime;
|
||||
|
||||
Throttler({required this.duration});
|
||||
|
||||
void run(VoidCallback action) {
|
||||
if (lastActionTime == null) {
|
||||
lastActionTime = DateTime.now().millisecondsSinceEpoch;
|
||||
action();
|
||||
} else {
|
||||
if (DateTime.now().millisecondsSinceEpoch - lastActionTime! > (duration.inMilliseconds)) {
|
||||
lastActionTime = DateTime.now().millisecondsSinceEpoch;
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue