153 lines
3.4 KiB
Dart
153 lines
3.4 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:qhd_prevention/tools/click_util.dart';
|
||
|
|
|
||
|
|
class GuardedGestureDetector extends StatelessWidget {
|
||
|
|
final Widget child;
|
||
|
|
final GuardedTapCallback? onTap;
|
||
|
|
final Object? guardKey;
|
||
|
|
final int delayMs;
|
||
|
|
final bool lockDuringExecution;
|
||
|
|
final HitTestBehavior? behavior;
|
||
|
|
|
||
|
|
const GuardedGestureDetector({
|
||
|
|
super.key,
|
||
|
|
required this.child,
|
||
|
|
this.onTap,
|
||
|
|
this.guardKey,
|
||
|
|
this.delayMs = ClickUtil.defaultDelayMs,
|
||
|
|
this.lockDuringExecution = true,
|
||
|
|
this.behavior,
|
||
|
|
});
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return GestureDetector(
|
||
|
|
behavior: behavior,
|
||
|
|
onTap: ClickUtil.wrap(
|
||
|
|
onTap,
|
||
|
|
key: guardKey,
|
||
|
|
delayMs: delayMs,
|
||
|
|
lockDuringExecution: lockDuringExecution,
|
||
|
|
),
|
||
|
|
child: child,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class GuardedInkWell extends StatelessWidget {
|
||
|
|
final Widget child;
|
||
|
|
final GuardedTapCallback? onTap;
|
||
|
|
final Object? guardKey;
|
||
|
|
final int delayMs;
|
||
|
|
final bool lockDuringExecution;
|
||
|
|
final BorderRadius? borderRadius;
|
||
|
|
final Color? splashColor;
|
||
|
|
final Color? highlightColor;
|
||
|
|
|
||
|
|
const GuardedInkWell({
|
||
|
|
super.key,
|
||
|
|
required this.child,
|
||
|
|
this.onTap,
|
||
|
|
this.guardKey,
|
||
|
|
this.delayMs = ClickUtil.defaultDelayMs,
|
||
|
|
this.lockDuringExecution = true,
|
||
|
|
this.borderRadius,
|
||
|
|
this.splashColor,
|
||
|
|
this.highlightColor,
|
||
|
|
});
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return InkWell(
|
||
|
|
borderRadius: borderRadius,
|
||
|
|
splashColor: splashColor,
|
||
|
|
highlightColor: highlightColor,
|
||
|
|
onTap: ClickUtil.wrap(
|
||
|
|
onTap,
|
||
|
|
key: guardKey,
|
||
|
|
delayMs: delayMs,
|
||
|
|
lockDuringExecution: lockDuringExecution,
|
||
|
|
),
|
||
|
|
child: child,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class GuardedTextButton extends StatelessWidget {
|
||
|
|
final Widget child;
|
||
|
|
final GuardedTapCallback? onPressed;
|
||
|
|
final Object? guardKey;
|
||
|
|
final int delayMs;
|
||
|
|
final bool lockDuringExecution;
|
||
|
|
final ButtonStyle? style;
|
||
|
|
|
||
|
|
const GuardedTextButton({
|
||
|
|
super.key,
|
||
|
|
required this.child,
|
||
|
|
this.onPressed,
|
||
|
|
this.guardKey,
|
||
|
|
this.delayMs = ClickUtil.defaultDelayMs,
|
||
|
|
this.lockDuringExecution = true,
|
||
|
|
this.style,
|
||
|
|
});
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return TextButton(
|
||
|
|
style: style,
|
||
|
|
onPressed: ClickUtil.wrap(
|
||
|
|
onPressed,
|
||
|
|
key: guardKey,
|
||
|
|
delayMs: delayMs,
|
||
|
|
lockDuringExecution: lockDuringExecution,
|
||
|
|
),
|
||
|
|
child: child,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class GuardedIconButton extends StatelessWidget {
|
||
|
|
final Widget icon;
|
||
|
|
final GuardedTapCallback? onPressed;
|
||
|
|
final Object? guardKey;
|
||
|
|
final int delayMs;
|
||
|
|
final bool lockDuringExecution;
|
||
|
|
final EdgeInsetsGeometry? padding;
|
||
|
|
final BoxConstraints? constraints;
|
||
|
|
final double? iconSize;
|
||
|
|
final String? tooltip;
|
||
|
|
final Color? color;
|
||
|
|
|
||
|
|
const GuardedIconButton({
|
||
|
|
super.key,
|
||
|
|
required this.icon,
|
||
|
|
this.onPressed,
|
||
|
|
this.guardKey,
|
||
|
|
this.delayMs = ClickUtil.defaultDelayMs,
|
||
|
|
this.lockDuringExecution = true,
|
||
|
|
this.padding,
|
||
|
|
this.constraints,
|
||
|
|
this.iconSize,
|
||
|
|
this.tooltip,
|
||
|
|
this.color,
|
||
|
|
});
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return IconButton(
|
||
|
|
icon: icon,
|
||
|
|
padding: padding,
|
||
|
|
constraints: constraints,
|
||
|
|
iconSize: iconSize,
|
||
|
|
tooltip: tooltip,
|
||
|
|
color: color,
|
||
|
|
onPressed: ClickUtil.wrap(
|
||
|
|
onPressed,
|
||
|
|
key: guardKey,
|
||
|
|
delayMs: delayMs,
|
||
|
|
lockDuringExecution: lockDuringExecution,
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|