Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

146 rader
5.1 KiB

  1. import 'package:audio_waveforms/audio_waveforms.dart';
  2. import 'package:demo001/gen/assets.gen.dart';
  3. import 'package:demo001/tools/color_utils.dart';
  4. import 'package:demo001/tools/textStyle.dart';
  5. import 'package:gap/gap.dart';
  6. import 'package:get/get.dart';
  7. import 'package:flutter/material.dart';
  8. import 'TranslateLogic.dart';
  9. import 'TranslateState.dart';
  10. /*
  11. 录音测试场景
  12. */
  13. // ignore: must_be_immutable
  14. class TranslateScene extends StatelessWidget {
  15. final TranslateLogic logic = Get.put(TranslateLogic()); // 注册控制器
  16. final TranslateState state = Get.find<TranslateLogic>().state;
  17. TranslateScene({super.key});
  18. @override
  19. Widget build(BuildContext context) {
  20. double width = MediaQuery.of(context).size.width;
  21. double height = MediaQuery.of(context).size.height;
  22. return Scaffold(
  23. appBar: AppBar(
  24. title: Text(
  25. "同声传译",
  26. style: Style.navTitle,
  27. ),
  28. ),
  29. body: Obx(() => ListView.builder(
  30. itemCount: state.kdxfSentenceList.length,
  31. itemBuilder: (context, index) {
  32. var audio = state.kdxfSentenceList[index];
  33. return _buildAudioMessage(audio, width);
  34. },
  35. )),
  36. bottomNavigationBar: Padding(
  37. padding: const EdgeInsets.all(20.0),
  38. child: InkWell(
  39. onTap: logic.toggleCallStatus,
  40. child: Obx(() => Container(
  41. decoration: BoxDecoration(
  42. borderRadius: BorderRadius.circular(30),
  43. color: state.isRecording.value ? Colors.red : Colors.green,
  44. ),
  45. padding: EdgeInsets.symmetric(vertical: 15, horizontal: 40),
  46. child: Row(
  47. mainAxisAlignment: MainAxisAlignment.center,
  48. children: [
  49. Icon(
  50. state.isRecording.value ? Icons.call_end : Icons.mic,
  51. color: Colors.white,
  52. size: 30,
  53. ),
  54. SizedBox(width: 10),
  55. Text(
  56. state.isRecording.value ? '挂断' : '开始通话',
  57. style: TextStyle(color: Colors.white, fontSize: 18),
  58. ),
  59. ],
  60. ),
  61. )),
  62. ),
  63. ),
  64. );
  65. }
  66. // 构建语音消息
  67. Widget _buildAudioMessage(KDXFSentenceModel model, double width) {
  68. return Padding(
  69. padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
  70. child: Row(
  71. children: [
  72. const Gap(10),
  73. Assets.img.imageAi.image(width: 25, height: 25),
  74. const Gap(10),
  75. Flexible(
  76. child: ConstrainedBox(
  77. constraints: BoxConstraints(maxWidth: width * 0.7),
  78. child: Container(
  79. padding: EdgeInsets.all(10),
  80. margin: EdgeInsets.only(top: 10),
  81. decoration: BoxDecoration(
  82. borderRadius: BorderRadius.circular(12),
  83. color: bottomNavBg,
  84. ),
  85. child: Column(
  86. crossAxisAlignment: CrossAxisAlignment.start,
  87. children: [
  88. Text(
  89. textAlign: TextAlign.start,
  90. model.content,
  91. style: Style.normal,
  92. maxLines: 1000,
  93. ),
  94. Visibility(
  95. visible: model.transResult.isNotEmpty,
  96. child: Column(
  97. children: [
  98. Gap(5),
  99. Text(
  100. textAlign: TextAlign.start,
  101. model.transResult,
  102. style: Style.normal,
  103. maxLines: 1000,
  104. ),
  105. ],
  106. ), // 判断 transResult 是否为空
  107. ),
  108. Visibility(
  109. visible: model.audioDuration > 0,
  110. child: GestureDetector(
  111. onTap: () {
  112. logic.kdxfPlayAudio(model);
  113. },
  114. child: ClipRRect(
  115. borderRadius: BorderRadius.circular(5),
  116. child: AudioFileWaveforms(
  117. size: Size(165, 30),
  118. decoration: BoxDecoration(
  119. border: Border.all(color: orange, width: 0.5),
  120. borderRadius: BorderRadius.circular(5),
  121. ),
  122. enableSeekGesture: false,
  123. waveformType: WaveformType.fitWidth,
  124. playerWaveStyle: PlayerWaveStyle(
  125. waveThickness: 2, scaleFactor: 50),
  126. playerController: model.playerController,
  127. ),
  128. ),
  129. ),
  130. ),
  131. ],
  132. ),
  133. ),
  134. ),
  135. ),
  136. ],
  137. ),
  138. );
  139. }
  140. }