|
- import 'package:audio_waveforms/audio_waveforms.dart';
- import 'package:demo001/gen/assets.gen.dart';
- import 'package:demo001/tools/color_utils.dart';
- import 'package:demo001/tools/textStyle.dart';
- import 'package:gap/gap.dart';
- import 'package:get/get.dart';
- import 'package:flutter/material.dart';
- import 'TranslateLogic.dart';
- import 'TranslateState.dart';
-
- /*
- 录音测试场景
- */
- // ignore: must_be_immutable
- class TranslateScene extends StatelessWidget {
- final TranslateLogic logic = Get.put(TranslateLogic()); // 注册控制器
- final TranslateState state = Get.find<TranslateLogic>().state;
-
- TranslateScene({super.key});
-
- @override
- Widget build(BuildContext context) {
- double width = MediaQuery.of(context).size.width;
- double height = MediaQuery.of(context).size.height;
-
- return Scaffold(
- appBar: AppBar(
- title: Text(
- "同声传译",
- style: Style.navTitle,
- ),
- ),
- body: Obx(() => ListView.builder(
- itemCount: state.kdxfSentenceList.length,
- itemBuilder: (context, index) {
- var audio = state.kdxfSentenceList[index];
- return _buildAudioMessage(audio, width);
- },
- )),
- bottomNavigationBar: Padding(
- padding: const EdgeInsets.all(20.0),
- child: InkWell(
- onTap: logic.toggleCallStatus,
- child: Obx(() => Container(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(30),
- color: state.isRecording.value ? Colors.red : Colors.green,
- ),
- padding: EdgeInsets.symmetric(vertical: 15, horizontal: 40),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Icon(
- state.isRecording.value ? Icons.call_end : Icons.mic,
- color: Colors.white,
- size: 30,
- ),
- SizedBox(width: 10),
- Text(
- state.isRecording.value ? '挂断' : '开始通话',
- style: TextStyle(color: Colors.white, fontSize: 18),
- ),
- ],
- ),
- )),
- ),
- ),
- );
- }
-
- // 构建语音消息
- Widget _buildAudioMessage(KDXFSentenceModel model, double width) {
- return Padding(
- padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
- child: Row(
- children: [
- const Gap(10),
- Assets.img.imageAi.image(width: 25, height: 25),
- const Gap(10),
- Flexible(
- child: ConstrainedBox(
- constraints: BoxConstraints(maxWidth: width * 0.7),
- child: Container(
- padding: EdgeInsets.all(10),
- margin: EdgeInsets.only(top: 10),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- color: bottomNavBg,
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- textAlign: TextAlign.start,
- model.content,
- style: Style.normal,
- maxLines: 1000,
- ),
- Visibility(
- visible: model.transResult.isNotEmpty,
- child: Column(
- children: [
- Gap(5),
- Text(
- textAlign: TextAlign.start,
- model.transResult,
- style: Style.normal,
- maxLines: 1000,
- ),
- ],
- ), // 判断 transResult 是否为空
- ),
- Visibility(
- visible: model.audioDuration > 0,
- child: GestureDetector(
- onTap: () {
- logic.kdxfPlayAudio(model);
- },
- child: ClipRRect(
- borderRadius: BorderRadius.circular(5),
- child: AudioFileWaveforms(
- size: Size(165, 30),
- decoration: BoxDecoration(
- border: Border.all(color: orange, width: 0.5),
- borderRadius: BorderRadius.circular(5),
- ),
- enableSeekGesture: false,
- waveformType: WaveformType.fitWidth,
- playerWaveStyle: PlayerWaveStyle(
- waveThickness: 2, scaleFactor: 50),
- playerController: model.playerController,
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- ],
- ),
- );
- }
- }
|