detect_button.dart 5.5 KB

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