flutter/lib/components/animation.dart

42 lines
843 B
Dart
Raw Permalink Normal View History

2025-09-22 14:41:47 +08:00
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';
class VoiceAnimation extends StatelessWidget {
/// 是否正在播放
final bool isPlaying;
/// Lottie 动画资源路径
final String animationAsset;
/// 静态图标
final IconData idleIcon;
/// 动画和图标的大小
final double size;
const VoiceAnimation({
super.key,
required this.isPlaying,
this.animationAsset = 'assets/animation/voice.json',
this.idleIcon = Icons.multitrack_audio, // 静态图标
this.size = 24.0,
});
@override
Widget build(BuildContext context) {
if (isPlaying) {
return Lottie.asset(
animationAsset,
width: size,
height: size,
repeat: true,
);
} else {
return Icon(
idleIcon,
size: size,
);
}
}
}