Files
ai_chat_assistant/lib/widgets/floating_icon_with_wave.dart

61 lines
1.9 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:ai_chat_assistant/utils/assets_util.dart';
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: [
// 背景图片
AssetsUtil.getImageWidget(
'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, // 保持最大高度比例
),
),
),
],
),
);
}
}