2024-07-27 21:05:51 +08:00
|
|
|
import 'package:appflowy/shared/feedback_gesture_detector.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class AnimatedGestureDetector extends StatefulWidget {
|
|
|
|
const AnimatedGestureDetector({
|
|
|
|
super.key,
|
|
|
|
this.scaleFactor = 0.98,
|
|
|
|
this.feedback = true,
|
|
|
|
this.duration = const Duration(milliseconds: 100),
|
|
|
|
this.alignment = Alignment.center,
|
|
|
|
this.behavior = HitTestBehavior.opaque,
|
|
|
|
required this.onTapUp,
|
|
|
|
required this.child,
|
|
|
|
});
|
|
|
|
|
|
|
|
final Widget child;
|
|
|
|
final double scaleFactor;
|
|
|
|
final Duration duration;
|
|
|
|
final Alignment alignment;
|
|
|
|
final bool feedback;
|
|
|
|
final HitTestBehavior behavior;
|
|
|
|
final VoidCallback onTapUp;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<AnimatedGestureDetector> createState() =>
|
|
|
|
_AnimatedGestureDetectorState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AnimatedGestureDetectorState extends State<AnimatedGestureDetector> {
|
|
|
|
double scale = 1.0;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
|
|
|
behavior: widget.behavior,
|
|
|
|
onTapUp: (details) {
|
|
|
|
setState(() => scale = 1.0);
|
|
|
|
|
2024-07-30 19:53:11 +08:00
|
|
|
HapticFeedbackType.light.call();
|
2024-07-27 21:05:51 +08:00
|
|
|
|
|
|
|
widget.onTapUp();
|
|
|
|
},
|
|
|
|
onTapDown: (details) {
|
|
|
|
setState(() => scale = widget.scaleFactor);
|
|
|
|
},
|
|
|
|
child: AnimatedScale(
|
|
|
|
scale: scale,
|
|
|
|
alignment: widget.alignment,
|
|
|
|
duration: widget.duration,
|
|
|
|
child: widget.child,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|