88 lines
2.3 KiB
Dart
88 lines
2.3 KiB
Dart
|
|
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<StatusChip> createState() => _StatusChipState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _StatusChipState extends State<StatusChip>
|
||
|
|
with SingleTickerProviderStateMixin {
|
||
|
|
late AnimationController _controller;
|
||
|
|
late Animation<double> _opacityAnimation;
|
||
|
|
|
||
|
|
@override
|
||
|
|
void initState() {
|
||
|
|
super.initState();
|
||
|
|
_controller = AnimationController(
|
||
|
|
vsync: this,
|
||
|
|
duration: const Duration(milliseconds: 1000),
|
||
|
|
);
|
||
|
|
if (widget.breathing) _controller.repeat(reverse: true);
|
||
|
|
|
||
|
|
_opacityAnimation = Tween<double>(
|
||
|
|
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,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
},
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|