refactor: Trigger haptic feedback on tap down for immediate response
This commit is contained in:
@@ -64,75 +64,76 @@ class ConduitButton extends ConsumerWidget {
|
|||||||
label: semanticLabel,
|
label: semanticLabel,
|
||||||
button: true,
|
button: true,
|
||||||
enabled: !isLoading && onPressed != null,
|
enabled: !isLoading && onPressed != null,
|
||||||
child: SizedBox(
|
child: GestureDetector(
|
||||||
width: isFullWidth ? double.infinity : width,
|
// Trigger haptic feedback on tap down for immediate tactile response
|
||||||
height: isCompact ? TouchTarget.medium : TouchTarget.comfortable,
|
onTapDown: (onPressed != null && !isLoading)
|
||||||
child: ElevatedButton(
|
? (_) {
|
||||||
onPressed: isLoading
|
PlatformService.hapticFeedbackWithSettings(
|
||||||
? null
|
type: isDestructive ? HapticType.warning : HapticType.light,
|
||||||
: () {
|
hapticEnabled: hapticEnabled,
|
||||||
if (onPressed != null) {
|
);
|
||||||
PlatformService.hapticFeedbackWithSettings(
|
}
|
||||||
type: isDestructive
|
: null,
|
||||||
? HapticType.warning
|
child: SizedBox(
|
||||||
: HapticType.light,
|
width: isFullWidth ? double.infinity : width,
|
||||||
hapticEnabled: hapticEnabled,
|
height: isCompact ? TouchTarget.medium : TouchTarget.comfortable,
|
||||||
);
|
child: ElevatedButton(
|
||||||
onPressed!();
|
onPressed: isLoading ? null : onPressed,
|
||||||
}
|
style: ElevatedButton.styleFrom(
|
||||||
},
|
backgroundColor: backgroundColor,
|
||||||
style: ElevatedButton.styleFrom(
|
foregroundColor: textColor,
|
||||||
backgroundColor: backgroundColor,
|
disabledBackgroundColor: context.conduitTheme.buttonDisabled,
|
||||||
foregroundColor: textColor,
|
shape: RoundedRectangleBorder(
|
||||||
disabledBackgroundColor: context.conduitTheme.buttonDisabled,
|
borderRadius: BorderRadius.circular(AppBorderRadius.button),
|
||||||
shape: RoundedRectangleBorder(
|
),
|
||||||
borderRadius: BorderRadius.circular(AppBorderRadius.button),
|
elevation: Elevation.none,
|
||||||
|
shadowColor: backgroundColor.withValues(alpha: Alpha.standard),
|
||||||
|
minimumSize: Size(
|
||||||
|
TouchTarget.minimum,
|
||||||
|
isCompact ? TouchTarget.medium : TouchTarget.comfortable,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: isCompact ? Spacing.md : Spacing.buttonPadding,
|
||||||
|
vertical: isCompact ? Spacing.sm : Spacing.sm,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
elevation: Elevation.none,
|
child: isLoading
|
||||||
shadowColor: backgroundColor.withValues(alpha: Alpha.standard),
|
? Semantics(
|
||||||
minimumSize: Size(
|
label:
|
||||||
TouchTarget.minimum,
|
AppLocalizations.of(context)?.loadingContent ??
|
||||||
isCompact ? TouchTarget.medium : TouchTarget.comfortable,
|
'Loading',
|
||||||
),
|
excludeSemantics: true,
|
||||||
padding: EdgeInsets.symmetric(
|
child: SizedBox(
|
||||||
horizontal: isCompact ? Spacing.md : Spacing.buttonPadding,
|
width: IconSize.small,
|
||||||
vertical: isCompact ? Spacing.sm : Spacing.sm,
|
height: IconSize.small,
|
||||||
),
|
child: CircularProgressIndicator(
|
||||||
),
|
strokeWidth: 2,
|
||||||
child: isLoading
|
valueColor: AlwaysStoppedAnimation<Color>(textColor),
|
||||||
? Semantics(
|
|
||||||
label:
|
|
||||||
AppLocalizations.of(context)?.loadingContent ?? 'Loading',
|
|
||||||
excludeSemantics: true,
|
|
||||||
child: SizedBox(
|
|
||||||
width: IconSize.small,
|
|
||||||
height: IconSize.small,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 2,
|
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(textColor),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
if (icon != null) ...[
|
|
||||||
Icon(icon, size: IconSize.small),
|
|
||||||
SizedBox(width: Spacing.iconSpacing),
|
|
||||||
],
|
|
||||||
Flexible(
|
|
||||||
child: EnhancedAccessibilityService.createAccessibleText(
|
|
||||||
text,
|
|
||||||
style: AppTypography.standard.copyWith(
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: textColor,
|
|
||||||
),
|
|
||||||
maxLines: 1,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
)
|
||||||
),
|
: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
if (icon != null) ...[
|
||||||
|
Icon(icon, size: IconSize.small),
|
||||||
|
SizedBox(width: Spacing.iconSpacing),
|
||||||
|
],
|
||||||
|
Flexible(
|
||||||
|
child:
|
||||||
|
EnhancedAccessibilityService.createAccessibleText(
|
||||||
|
text,
|
||||||
|
style: AppTypography.standard.copyWith(
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: textColor,
|
||||||
|
),
|
||||||
|
maxLines: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user