mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
25 lines
689 B
Dart
25 lines
689 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
abstract final class Funcs {
|
|
static const int _defaultDurationTime = 377;
|
|
static const String _defaultThrottleId = 'default';
|
|
static final Map<String, int> startTimeMap = <String, int>{
|
|
_defaultThrottleId: 0
|
|
};
|
|
|
|
static void throttle(
|
|
VoidCallback? func, {
|
|
String id = _defaultThrottleId,
|
|
int duration = _defaultDurationTime,
|
|
Function? continueClick,
|
|
}) {
|
|
final currentTime = DateTime.now().millisecondsSinceEpoch;
|
|
if (currentTime - (startTimeMap[id] ?? 0) > duration) {
|
|
func?.call();
|
|
startTimeMap[id] = DateTime.now().millisecondsSinceEpoch;
|
|
} else {
|
|
continueClick?.call();
|
|
}
|
|
}
|
|
}
|