Files
social-app/apps/lib/shared/widgets/app_pressable.dart
T

48 lines
1.3 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
class AppPressable extends StatefulWidget {
const AppPressable({
super.key,
required this.child,
this.onTap,
this.borderRadius,
this.pressedScale = 0.97,
});
final Widget child;
final VoidCallback? onTap;
final BorderRadius? borderRadius;
final double pressedScale;
@override
State<AppPressable> createState() => _AppPressableState();
}
class _AppPressableState extends State<AppPressable> {
bool _isPressed = false;
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return AnimatedScale(
scale: _isPressed ? widget.pressedScale : 1,
duration: const Duration(milliseconds: 110),
curve: Curves.easeOut,
child: Material(
color: colorScheme.surface.withValues(alpha: 0),
child: InkWell(
borderRadius: widget.borderRadius,
onTap: widget.onTap,
onHighlightChanged: (pressed) {
if (_isPressed == pressed) return;
setState(() => _isPressed = pressed);
},
splashColor: colorScheme.primary.withValues(alpha: 0.12),
highlightColor: colorScheme.primary.withValues(alpha: 0.08),
child: widget.child,
),
),
);
}
}