增加悬浮“众众”的定时图片切换效果
This commit is contained in:
BIN
assets/images/ai0_hd.png
Normal file
BIN
assets/images/ai0_hd.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
@@ -4,6 +4,7 @@ import '../services/message_service.dart';
|
|||||||
import '../screens/full_screen.dart';
|
import '../screens/full_screen.dart';
|
||||||
import '../screens/part_screen.dart';
|
import '../screens/part_screen.dart';
|
||||||
import 'floating_icon_with_wave.dart';
|
import 'floating_icon_with_wave.dart';
|
||||||
|
import 'dart:async'; // 添加此行
|
||||||
|
|
||||||
class FloatingIcon extends StatefulWidget {
|
class FloatingIcon extends StatefulWidget {
|
||||||
const FloatingIcon({super.key});
|
const FloatingIcon({super.key});
|
||||||
@@ -17,22 +18,36 @@ class _FloatingIconState extends State<FloatingIcon>
|
|||||||
Offset _position = const Offset(10, 120);
|
Offset _position = const Offset(10, 120);
|
||||||
final iconSize = 80.0;
|
final iconSize = 80.0;
|
||||||
bool _isShowPartScreen = false;
|
bool _isShowPartScreen = false;
|
||||||
|
|
||||||
late AnimationController _waveAnimationController;
|
late AnimationController _waveAnimationController;
|
||||||
|
|
||||||
|
// 新增:图片切换相关
|
||||||
|
int _imageIndex = 0;
|
||||||
|
late final List<String> _iconImages = [
|
||||||
|
'assets/images/ai1_hd.png',
|
||||||
|
'assets/images/ai0_hd.png',
|
||||||
|
];
|
||||||
|
Timer? _imageTimer; // 用于定时切换图片
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// VehicleStateService();
|
|
||||||
_waveAnimationController = AnimationController(
|
_waveAnimationController = AnimationController(
|
||||||
duration: const Duration(milliseconds: 1000),
|
duration: const Duration(milliseconds: 1000),
|
||||||
vsync: this,
|
vsync: this,
|
||||||
);
|
);
|
||||||
|
// 使用Timer.periodic定时切换图片
|
||||||
|
_imageTimer = Timer.periodic(const Duration(seconds: 3), (timer) {
|
||||||
|
setState(() {
|
||||||
|
_imageIndex = (_imageIndex + 1) % _iconImages.length;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_waveAnimationController.dispose();
|
_waveAnimationController.dispose();
|
||||||
|
_imageTimer?.cancel(); // 释放Timer
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +95,6 @@ class _FloatingIconState extends State<FloatingIcon>
|
|||||||
right: _position.dx,
|
right: _position.dx,
|
||||||
child: Consumer<MessageService>(
|
child: Consumer<MessageService>(
|
||||||
builder: (context, messageService, child) {
|
builder: (context, messageService, child) {
|
||||||
// 立即响应录音状态变化,控制动画
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (messageService.isRecording) {
|
if (messageService.isRecording) {
|
||||||
if (!_waveAnimationController.isAnimating) {
|
if (!_waveAnimationController.isAnimating) {
|
||||||
@@ -92,17 +106,15 @@ class _FloatingIconState extends State<FloatingIcon>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: _showFullScreen,
|
onTap: _showFullScreen,
|
||||||
onLongPress: () async {
|
onLongPress: () async {
|
||||||
_showPartScreen();
|
_showPartScreen();
|
||||||
// 立即启动动画
|
|
||||||
_waveAnimationController.repeat();
|
_waveAnimationController.repeat();
|
||||||
await messageService.startVoiceInput();
|
await messageService.startVoiceInput();
|
||||||
},
|
},
|
||||||
onLongPressUp: () async {
|
onLongPressUp: () async {
|
||||||
// 立即停止动画
|
|
||||||
_waveAnimationController.stop();
|
_waveAnimationController.stop();
|
||||||
await messageService.stopAndProcessVoiceInput();
|
await messageService.stopAndProcessVoiceInput();
|
||||||
final hasMessage = messageService.messages.isNotEmpty;
|
final hasMessage = messageService.messages.isNotEmpty;
|
||||||
@@ -118,7 +130,7 @@ class _FloatingIconState extends State<FloatingIcon>
|
|||||||
waveColor: Colors.white,
|
waveColor: Colors.white,
|
||||||
)
|
)
|
||||||
: Image.asset(
|
: Image.asset(
|
||||||
'assets/images/ai1_hd.png',
|
_iconImages[_imageIndex],
|
||||||
width: iconSize,
|
width: iconSize,
|
||||||
height: iconSize,
|
height: iconSize,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user