增加悬浮图标的声波动画效果

This commit is contained in:
2025-08-12 17:40:39 +08:00
parent 4035804b73
commit 15680677fc
6 changed files with 153 additions and 36 deletions

View File

@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'mini_audio_wave.dart';
/// 浮动图标与声波动画组合组件
///
/// 将ai_hd_clean.png图片和AudioWaveLargeMini声波效果组合成一个独立组件
class FloatingIconWithWave extends StatelessWidget {
/// 动画控制器,用于驱动声波动画
final AnimationController animationController;
/// 图标大小
final double iconSize;
/// 声波颜色,默认为白色
final Color waveColor;
/// 构造函数
const FloatingIconWithWave({
super.key,
required this.animationController,
required this.iconSize,
this.waveColor = Colors.white,
});
@override
Widget build(BuildContext context) {
return SizedBox(
width: iconSize,
height: iconSize,
child: Stack(
alignment: Alignment.center,
children: [
// 背景图片
Image.asset(
'assets/images/ai_hd_clean.png',
width: iconSize,
height: iconSize,
fit: BoxFit.contain,
),
// 声波动画距离底部13px的位置
Positioned(
bottom: 13 * (iconSize / 198), // 按比例计算距离底部的位置
child: SizedBox(
width: 96 * (iconSize / 144), // 最宽不超过96px按图片原始宽度比例
height: 27 * (iconSize / 198), // 最高不超过27px按图片原始高度比例
child: AudioWaveLargeMini(
animationController: animationController,
waveColor: waveColor,
barSpacing: 2.5, // 减小间距以适应更小的宽度
minHeightRatio: 0.4, // 调整最小高度比例
maxHeightRatio: 1.0, // 保持最大高度比例
),
),
),
],
),
);
}
}