Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

153 řádky
5.7 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. double width = 0;
  19. double height = 0;
  20. @override
  21. Widget build(BuildContext context) {
  22. width = MediaQuery.of(context).size.width;
  23. height = MediaQuery.of(context).size.height;
  24. return Scaffold(
  25. appBar: AppBar(
  26. title: Text(
  27. "同声传译",
  28. style: Style.navTitle,
  29. )),
  30. body: ListView.builder(
  31. itemCount: state.kdxfSentenceList.length,
  32. itemBuilder: (context, index) {
  33. var audio = state.kdxfSentenceList[index];
  34. return _buildAudioMessage(audio);
  35. },
  36. ),
  37. bottomNavigationBar: Padding(
  38. padding: const EdgeInsets.all(20.0),
  39. child: InkWell(
  40. onTap: logic.toggleCallStatus,
  41. child: Obx(() => Container(
  42. decoration: BoxDecoration(
  43. borderRadius: BorderRadius.circular(30), // 圆角按钮
  44. color: state.isRecording.value
  45. ? Colors.red
  46. : Colors.green, // 通话状态红色,非通话状态绿色
  47. ),
  48. padding: EdgeInsets.symmetric(
  49. vertical: 15, horizontal: 40), // 调整按钮大小
  50. child: Row(
  51. mainAxisAlignment: MainAxisAlignment.center,
  52. children: [
  53. Icon(
  54. state.isRecording.value
  55. ? Icons.call_end
  56. : Icons.mic, // 图标变化
  57. color: Colors.white,
  58. size: 30,
  59. ),
  60. SizedBox(width: 10),
  61. Text(
  62. state.isRecording.value ? '挂断' : '开始通话', // 状态文字变化
  63. style: TextStyle(
  64. color: Colors.white,
  65. fontSize: 18,
  66. ),
  67. ),
  68. ],
  69. ),
  70. )))),
  71. );
  72. }
  73. // 构建语音消息
  74. Widget _buildAudioMessage(KDXFSentenceModel model) {
  75. return Padding(
  76. padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
  77. child: Row(
  78. children: [
  79. const Gap(10),
  80. Assets.img.imageAi.image(width: 25, height: 25),
  81. const Gap(10),
  82. Flexible(
  83. child: ConstrainedBox(
  84. constraints: BoxConstraints(maxWidth: width * 0.7),
  85. child: Container(
  86. padding: EdgeInsets.all(10),
  87. margin: EdgeInsets.only(top: 10),
  88. decoration: BoxDecoration(
  89. borderRadius: BorderRadius.circular(12),
  90. color: bottomNavBg,
  91. ),
  92. child: Column(
  93. crossAxisAlignment: CrossAxisAlignment.start,
  94. children: [
  95. Text(
  96. textAlign: TextAlign.start,
  97. model.content,
  98. style: Style.normal,
  99. maxLines: 1000,
  100. ),
  101. Obx(() => Visibility(
  102. visible: model.transResult != '', child: Gap(5))),
  103. Obx(() => Visibility(
  104. visible: model.transResult != '',
  105. child: Text(
  106. textAlign: TextAlign.start,
  107. model.transResult,
  108. style: Style.normal,
  109. maxLines: 1000,
  110. ),
  111. )),
  112. Obx(() => Visibility(
  113. visible: model.audioDuration > 0,
  114. child: const Gap(10),
  115. )),
  116. Obx(
  117. () => Visibility(
  118. visible: model.audioDuration > 0,
  119. child: GestureDetector(
  120. onTap: () {
  121. logic.kdxfPlayAudio(model);
  122. },
  123. child: ClipRRect(
  124. borderRadius: BorderRadius.circular(5),
  125. child: AudioFileWaveforms(
  126. size: Size(165, 30),
  127. decoration: BoxDecoration(
  128. border: Border.all(color: orange, width: 0.5),
  129. borderRadius: BorderRadius.circular(5),
  130. ),
  131. enableSeekGesture: false,
  132. waveformType: WaveformType.fitWidth,
  133. playerWaveStyle: PlayerWaveStyle(
  134. waveThickness: 2, scaleFactor: 50),
  135. playerController: model.playerController,
  136. ),
  137. ),
  138. ),
  139. ),
  140. )
  141. ],
  142. ),
  143. ),
  144. ),
  145. ),
  146. ],
  147. ),
  148. );
  149. }
  150. }