92 lines
3.3 KiB
Dart
92 lines
3.3 KiB
Dart
import 'package:basic_intl/intl.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../services/message_service.dart';
|
|
import '../utils/common_util.dart';
|
|
import 'voice_animation.dart';
|
|
|
|
class ChatFooter extends StatelessWidget {
|
|
final VoidCallback? onClear;
|
|
|
|
const ChatFooter({super.key, this.onClear});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
color: Colors.transparent,
|
|
child: Row(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 12, bottom: 12),
|
|
child: IconButton(
|
|
icon: const Icon(Icons.delete_outline,
|
|
color: CommonUtil.commonColor),
|
|
iconSize: 30,
|
|
tooltip: '清除会话',
|
|
onPressed: onClear,
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(bottom: 12),
|
|
child: Consumer<MessageService>(
|
|
builder: (context, messageService, child) {
|
|
return GestureDetector(
|
|
onTap: () {
|
|
HapticFeedback.heavyImpact();
|
|
messageService.abortReply();
|
|
},
|
|
onLongPress: () {
|
|
HapticFeedback.mediumImpact();
|
|
Future.delayed(const Duration(milliseconds: 100), () {
|
|
HapticFeedback.heavyImpact();
|
|
});
|
|
messageService.startVoiceInput();
|
|
},
|
|
onLongPressUp: () {
|
|
HapticFeedback.lightImpact();
|
|
messageService.stopAndProcessVoiceInput();
|
|
},
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 150),
|
|
height: 48,
|
|
width: double.infinity,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: messageService.isRecording
|
|
? Color(0xFF8E24AA).withValues(alpha: 0.42)
|
|
: Colors.white.withValues(alpha: 0.12),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: messageService.isRecording
|
|
? const VoiceWaveAnimation()
|
|
: Text(
|
|
Intl.getCurrentLocale().startsWith('zh')
|
|
? '按 住 说 话'
|
|
: 'Hold to Speak',
|
|
style: TextStyle(
|
|
color: CommonUtil.commonColor,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 12, right: 12),
|
|
child: IconButton(
|
|
icon: const Icon(Icons.keyboard, color: CommonUtil.commonColor),
|
|
iconSize: 30,
|
|
onPressed: () {},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|