detect_button.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import 'package:flutter/material.dart';
  2. import 'package:fis_ui/index.dart';
  3. import 'package:fis_ui/base_define/page.dart';
  4. import 'package:get/get.dart';
  5. import '../index.dart';
  6. /// 设备检测按钮
  7. class DetectButton extends GetView<HardwareDetectionController>
  8. implements FPage {
  9. DetectButton({
  10. Key? key,
  11. required this.deviceType,
  12. this.subTitleRowHright = 30.0,
  13. }) : super(key: key);
  14. @override
  15. String get pageName => "detect_button";
  16. final HardwareDeviceType deviceType;
  17. /// 副标题行高:[是否能看到画面变化]
  18. final double subTitleRowHright;
  19. /// 检测按钮文案
  20. String get detectButtonText {
  21. switch (deviceType) {
  22. case HardwareDeviceType.camera:
  23. return "检测摄像头";
  24. case HardwareDeviceType.speaker:
  25. return "检测扬声器";
  26. case HardwareDeviceType.microphone:
  27. return "检测麦克风";
  28. default:
  29. return "";
  30. }
  31. }
  32. /// 检测中询问文案
  33. String get detectingAskText {
  34. switch (deviceType) {
  35. case HardwareDeviceType.camera:
  36. return "是否能看到画面?";
  37. case HardwareDeviceType.speaker:
  38. return "是否能听到音乐?";
  39. case HardwareDeviceType.microphone:
  40. return "是否能看到音量条变化?";
  41. default:
  42. return "";
  43. }
  44. }
  45. List<HardwareDevice> get deviceList {
  46. switch (deviceType) {
  47. case HardwareDeviceType.camera:
  48. return controller.state.cameraList;
  49. case HardwareDeviceType.speaker:
  50. return controller.state.speakerList;
  51. case HardwareDeviceType.microphone:
  52. return controller.state.microphoneList;
  53. default:
  54. return [];
  55. }
  56. }
  57. bool get detectingDevice {
  58. switch (deviceType) {
  59. case HardwareDeviceType.camera:
  60. return controller.state.detectingCamera;
  61. case HardwareDeviceType.speaker:
  62. return controller.state.detectingSpeaker;
  63. case HardwareDeviceType.microphone:
  64. return controller.state.detectingMicrophone;
  65. default:
  66. return false;
  67. }
  68. }
  69. Function get setDeviceAvailable {
  70. switch (deviceType) {
  71. case HardwareDeviceType.camera:
  72. return controller.setCameraAvailable;
  73. case HardwareDeviceType.speaker:
  74. return controller.setSpeakerAvailable;
  75. case HardwareDeviceType.microphone:
  76. return controller.setMicrophoneAvailable;
  77. default:
  78. return () {};
  79. }
  80. }
  81. Function get startDetectDevice {
  82. switch (deviceType) {
  83. case HardwareDeviceType.camera:
  84. return controller.startDetectingCamera;
  85. case HardwareDeviceType.speaker:
  86. return controller.startDetectingSpeaker;
  87. case HardwareDeviceType.microphone:
  88. return controller.startDetectingMicrophone;
  89. default:
  90. return () {};
  91. }
  92. }
  93. @override
  94. Widget build(BuildContext context) {
  95. return Obx(
  96. () {
  97. bool noDevice = deviceList.isEmpty;
  98. bool isDetectingDevice = detectingDevice;
  99. if (noDevice) return Container();
  100. if (isDetectingDevice) {
  101. return FColumn(
  102. crossAxisAlignment: CrossAxisAlignment.start,
  103. children: [
  104. FContainer(
  105. height: subTitleRowHright,
  106. child: FCenter(
  107. child: FText(
  108. detectingAskText,
  109. style: TextStyle(fontSize: 14, height: 1),
  110. ),
  111. ),
  112. ),
  113. FRow(
  114. children: [
  115. FInkWell(
  116. child: Container(
  117. padding:
  118. EdgeInsets.symmetric(horizontal: 15, vertical: 5),
  119. decoration: BoxDecoration(
  120. border: Border.all(color: Colors.green, width: 2),
  121. borderRadius: BorderRadius.circular(5),
  122. ),
  123. child: FText(
  124. "是",
  125. style: TextStyle(
  126. fontSize: 14, color: Colors.green, height: 1),
  127. ),
  128. ),
  129. onTap: () {
  130. setDeviceAvailable(true);
  131. },
  132. ),
  133. FSizedBox(
  134. width: 5,
  135. ),
  136. FInkWell(
  137. child: Container(
  138. padding:
  139. EdgeInsets.symmetric(horizontal: 15, vertical: 5),
  140. decoration: BoxDecoration(
  141. border: Border.all(color: Colors.red, width: 2),
  142. borderRadius: BorderRadius.circular(5),
  143. ),
  144. child: FText(
  145. "否",
  146. style: TextStyle(
  147. fontSize: 14, color: Colors.red, height: 1),
  148. ),
  149. ),
  150. onTap: () {
  151. setDeviceAvailable(false);
  152. },
  153. ),
  154. ],
  155. ),
  156. ],
  157. );
  158. } else {
  159. return FColumn(
  160. crossAxisAlignment: CrossAxisAlignment.start,
  161. children: [
  162. FSizedBox(
  163. height: subTitleRowHright,
  164. ),
  165. /// FIXME 检测摄像头按钮 [外部无法直接使用 FElevatedButton,因为获取不到全局 env 参数]
  166. // FElevatedButton(
  167. // businessParent: this,
  168. // name: "startDetectingCamera",
  169. // child: FText(detectButtonText),
  170. // onPressed: () {
  171. // startDetectDevice();
  172. // },
  173. // ),
  174. FInkWell(
  175. child: FText(
  176. detectButtonText,
  177. style: TextStyle(fontSize: 14, color: Colors.blue, height: 1),
  178. ),
  179. onTap: () {
  180. startDetectDevice();
  181. },
  182. ),
  183. ],
  184. );
  185. }
  186. },
  187. );
  188. }
  189. }