state.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import 'package:get/get.dart';
  2. class HardwareDetectionState {
  3. /// *** 数据层状态 ***
  4. ///
  5. /// 数据层状态是指在 [Controller] 中的状态,用于控制数据的获取和存储。
  6. /// 设备列表
  7. List<HardwareDevice> _deviceList = [];
  8. set deviceList(List<HardwareDevice> value) => _deviceList = value;
  9. List<HardwareDevice> get deviceList => _deviceList;
  10. /// *** UI 层状态 ***
  11. ///
  12. /// UI 层状态是指在 [View] 中的状态,用于控制页面的显示效果。
  13. /// UI 层状态通常是通过 [Rx] 类型的变量来实现的。
  14. /// 摄像头初始化完成
  15. RxBool _isDisplayCameraWindow = RxBool(false);
  16. /// 扬声器初始化完成
  17. RxBool _isDisplaySpeakerWave = RxBool(false);
  18. /// 麦克风初始化完成
  19. RxBool _isDisplayMicrophoneWave = RxBool(false);
  20. /// 摄像头列表
  21. RxList<HardwareDevice> _cameraList = RxList<HardwareDevice>([]);
  22. /// 麦克风列表
  23. RxList<HardwareDevice> _microphoneList = RxList<HardwareDevice>([]);
  24. /// 扬声器列表
  25. RxList<HardwareDevice> _speakerList = RxList<HardwareDevice>([]);
  26. /// 当前选中的摄像头
  27. Rx<HardwareDevice?> _currentCamera = Rx<HardwareDevice?>(null);
  28. /// 当前选中的麦克风
  29. Rx<HardwareDevice?> _currentMicrophone = Rx<HardwareDevice?>(null);
  30. /// 当前选中的扬声器
  31. Rx<HardwareDevice?> _currentSpeaker = Rx<HardwareDevice?>(null);
  32. /// 当前摄像头可用性
  33. Rx<bool?> _cameraAvailable = Rx(null);
  34. /// 当前麦克风可用性
  35. Rx<bool?> _microphoneAvailable = Rx(null);
  36. /// 当前扬声器可用性
  37. Rx<bool?> _speakerAvailable = Rx(null);
  38. /// 是否正在检测摄像头
  39. RxBool _detectingCamera = RxBool(false);
  40. /// 是否正在检测麦克风
  41. RxBool _detectingMicrophone = RxBool(false);
  42. /// 是否正在检测扬声器
  43. RxBool _detectingSpeaker = RxBool(false);
  44. set isDisplayMicrophoneWave(bool value) =>
  45. _isDisplayMicrophoneWave.value = value;
  46. bool get isDisplayMicrophoneWave => _isDisplayMicrophoneWave.value;
  47. set isDisplaySpeakerWave(bool value) => _isDisplaySpeakerWave.value = value;
  48. bool get isDisplaySpeakerWave => _isDisplaySpeakerWave.value;
  49. set isDisplayCameraWindow(bool value) => _isDisplayCameraWindow.value = value;
  50. bool get isDisplayCameraWindow => _isDisplayCameraWindow.value;
  51. set cameraList(List<HardwareDevice> value) => _cameraList.value = value;
  52. List<HardwareDevice> get cameraList => _cameraList;
  53. set currentCamera(HardwareDevice? value) => _currentCamera = Rx(value);
  54. HardwareDevice? get currentCamera => _currentCamera.value;
  55. set microphoneList(List<HardwareDevice> value) =>
  56. _microphoneList.value = value;
  57. List<HardwareDevice> get microphoneList => _microphoneList;
  58. set currentMicrophone(HardwareDevice? value) =>
  59. _currentMicrophone = Rx(value);
  60. HardwareDevice? get currentMicrophone => _currentMicrophone.value;
  61. set speakerList(List<HardwareDevice> value) => _speakerList.value = value;
  62. List<HardwareDevice> get speakerList => _speakerList;
  63. set currentSpeaker(HardwareDevice? value) => _currentSpeaker = Rx(value);
  64. HardwareDevice? get currentSpeaker => _currentSpeaker.value;
  65. set cameraAvailable(bool? value) => _cameraAvailable.value = value;
  66. bool? get cameraAvailable => _cameraAvailable.value;
  67. set microphoneAvailable(bool? value) => _microphoneAvailable.value = value;
  68. bool? get microphoneAvailable => _microphoneAvailable.value;
  69. set speakerAvailable(bool? value) => _speakerAvailable.value = value;
  70. bool? get speakerAvailable => _speakerAvailable.value;
  71. set detectingCamera(bool value) => _detectingCamera.value = value;
  72. bool get detectingCamera => _detectingCamera.value;
  73. set detectingMicrophone(bool value) => _detectingMicrophone.value = value;
  74. bool get detectingMicrophone => _detectingMicrophone.value;
  75. set detectingSpeaker(bool value) => _detectingSpeaker.value = value;
  76. bool get detectingSpeaker => _detectingSpeaker.value;
  77. }
  78. class HardwareDevice {
  79. /// 设备名称
  80. String name;
  81. /// 设备id
  82. String id;
  83. /// 设备类型
  84. HardwareDeviceType type;
  85. HardwareDevice({required this.name, required this.id, required this.type});
  86. }
  87. enum HardwareDeviceType {
  88. /// 摄像头
  89. camera,
  90. /// 扬声器
  91. speaker,
  92. /// 麦克风
  93. microphone,
  94. }