chatapp3-flutter/lib/ui_kit/components/anim/sc_scaled_button.dart
2026-04-09 21:32:23 +08:00

58 lines
1.4 KiB
Dart

import 'package:flutter/material.dart';
/// 按钮按下缩小,离开还原
class SCScaledButton extends StatefulWidget {
final Widget child;
final VoidCallback? onClick;
const SCScaledButton({Key? key, required this.child, this.onClick}) : super(key: key);
@override
_ScaledButtonState createState() => _ScaledButtonState();
}
class _ScaledButtonState extends State<SCScaledButton> with TickerProviderStateMixin{
late AnimationController controller;
late Animation<double> tween;
@override
void initState() {
super.initState();
controller = AnimationController(duration: const Duration(milliseconds: 100), vsync: this);
tween = Tween(begin:1.0, end:1.5).animate(controller);
}
@override
void dispose() {
super.dispose();
controller?.dispose();
}
@override
Widget build(BuildContext context) {
return Material(
color: Colors.transparent,
child: ScaleTransition(
scale: tween,
alignment: Alignment.center,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: widget.onClick,
onTapDown: (details){
controller.forward();
},
onTapUp: (details){
controller.reset();
},
onTapCancel: (){
controller.reset();
},
child: widget.child,
),
),
);
}
}