refactor: Trigger haptic feedback on tap down for immediate response

This commit is contained in:
cogwheel0
2025-10-14 22:35:27 +05:30
parent 762155500b
commit 146cbfb492

View File

@@ -64,23 +64,21 @@ class ConduitButton extends ConsumerWidget {
label: semanticLabel,
button: true,
enabled: !isLoading && onPressed != null,
child: GestureDetector(
// Trigger haptic feedback on tap down for immediate tactile response
onTapDown: (onPressed != null && !isLoading)
? (_) {
PlatformService.hapticFeedbackWithSettings(
type: isDestructive ? HapticType.warning : HapticType.light,
hapticEnabled: hapticEnabled,
);
}
: null,
child: SizedBox(
width: isFullWidth ? double.infinity : width,
height: isCompact ? TouchTarget.medium : TouchTarget.comfortable,
child: ElevatedButton(
onPressed: isLoading
? null
: () {
if (onPressed != null) {
PlatformService.hapticFeedbackWithSettings(
type: isDestructive
? HapticType.warning
: HapticType.light,
hapticEnabled: hapticEnabled,
);
onPressed!();
}
},
onPressed: isLoading ? null : onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: backgroundColor,
foregroundColor: textColor,
@@ -102,7 +100,8 @@ class ConduitButton extends ConsumerWidget {
child: isLoading
? Semantics(
label:
AppLocalizations.of(context)?.loadingContent ?? 'Loading',
AppLocalizations.of(context)?.loadingContent ??
'Loading',
excludeSemantics: true,
child: SizedBox(
width: IconSize.small,
@@ -122,7 +121,8 @@ class ConduitButton extends ConsumerWidget {
SizedBox(width: Spacing.iconSpacing),
],
Flexible(
child: EnhancedAccessibilityService.createAccessibleText(
child:
EnhancedAccessibilityService.createAccessibleText(
text,
style: AppTypography.standard.copyWith(
fontWeight: FontWeight.w600,
@@ -135,6 +135,7 @@ class ConduitButton extends ConsumerWidget {
),
),
),
),
);
}
}