import 'package:flutter/material.dart'; class StatusChip extends StatefulWidget { final String text; final Color color; final IconData icon; final bool breathing; // 是否开启呼吸灯特效 final VoidCallback? onTap; const StatusChip({ super.key, required this.text, required this.color, required this.icon, this.breathing = false, this.onTap, }); @override State createState() => _StatusChipState(); } class _StatusChipState extends State with SingleTickerProviderStateMixin { late AnimationController _controller; late Animation _opacityAnimation; @override void initState() { super.initState(); _controller = AnimationController( vsync: this, duration: const Duration(milliseconds: 1000), ); if (widget.breathing) _controller.repeat(reverse: true); _opacityAnimation = Tween( begin: 0.4, end: 1.0, ).animate(CurvedAnimation(parent: _controller, curve: Curves.linear)); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return AnimatedBuilder( animation: _opacityAnimation, builder: (context, child) { final currentAlpha = widget.breathing ? _opacityAnimation.value : 0.6; return GestureDetector( onTap: widget.onTap, child: Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6), decoration: BoxDecoration( color: widget.color.withOpacity(currentAlpha), borderRadius: BorderRadius.circular(10), border: Border.all( color: widget.color.withOpacity(0.35), width: 0.5, ), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(widget.icon, color: Colors.white, size: 14), const SizedBox(width: 6), Text( widget.text, style: const TextStyle( color: Colors.white, fontSize: 12, fontWeight: FontWeight.bold, ), ), ], ), ), ); }, ); } }