camera_detection.dart 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../index.dart';
  4. import 'widgets.dart';
  5. /// 摄像头检测
  6. class CameraDetection extends GetView<HardwareDetectionController> {
  7. CameraDetection({Key? key}) : super(key: key);
  8. final smallTitleStyle = TextStyle(
  9. fontSize: 14,
  10. fontWeight: FontWeight.bold,
  11. height: 1,
  12. );
  13. /// 副标题行高:[摄像头]、[麦克风]、[扬声器]
  14. static const _subTitleRowHright = 30.0;
  15. @override
  16. Widget build(BuildContext context) {
  17. return Container(
  18. width: 300,
  19. child: Column(
  20. children: [
  21. Column(
  22. crossAxisAlignment: CrossAxisAlignment.start,
  23. children: [
  24. Container(
  25. width: 300,
  26. height: _subTitleRowHright,
  27. child: Row(
  28. children: [
  29. // Text("i18nBook.setting.camera.t", style: smallTitleStyle),
  30. Text("摄像头", style: smallTitleStyle),
  31. SizedBox(width: 10),
  32. Obx(() {
  33. if (controller.state.cameraAvailable == null)
  34. return Container();
  35. return controller.state.cameraAvailable!
  36. ? CommonWidgets.deviceAvailableTip()
  37. : CommonWidgets.deviceUnavailableTip();
  38. }),
  39. Expanded(child: Container()),
  40. InkWell(
  41. onTap: controller.refreshCameraList,
  42. child: Icon(
  43. Icons.refresh,
  44. size: 18,
  45. ),
  46. )
  47. ],
  48. ),
  49. ),
  50. Container(width: 300, child: _cameraSelector()),
  51. ],
  52. ),
  53. DetectButton(
  54. deviceType: HardwareDeviceType.camera,
  55. subTitleRowHright: _subTitleRowHright,
  56. ),
  57. ],
  58. ),
  59. );
  60. }
  61. /// 摄像头选择器
  62. Widget _cameraSelector() {
  63. return Obx(
  64. () {
  65. List<HardwareDevice> source = controller.state.cameraList;
  66. bool noCamera =
  67. source.isEmpty || controller.state.currentCameraId.isEmpty;
  68. if (controller.state.searchingCamera)
  69. return CommonWidgets.deviceFindingTip();
  70. return noCamera
  71. ? CommonWidgets.deviceNotFoundTip()
  72. : DropdownButton<String>(
  73. isExpanded: true,
  74. value: controller.state.currentCameraId,
  75. items: source.map((HardwareDevice device) {
  76. return DropdownMenuItem<String>(
  77. value: device.id,
  78. child: Text(device.name),
  79. );
  80. }).toList(),
  81. onChanged: (String? value) {
  82. if (value == null) return;
  83. controller.selectCameraById(value);
  84. },
  85. style: TextStyle(
  86. fontSize: 14,
  87. ),
  88. dropdownColor: Colors.white,
  89. underline: Container(
  90. height: 1,
  91. color: Colors.grey,
  92. ),
  93. );
  94. // : FSelect<HardwareDevice, String>(
  95. // source: source,
  96. // height: 30,
  97. // width: 300,
  98. // value: controller.state.currentCamera?.id,
  99. // optionValueExtractor: (value) {
  100. // return value.id;
  101. // },
  102. // optionLabelExtractor: (value) {
  103. // return value.name;
  104. // },
  105. // onSelectChanged: (value, index) {
  106. // if (value == null) return;
  107. // controller.selectCameraById(value);
  108. // },
  109. // fontSize: 14,
  110. // );
  111. },
  112. );
  113. }
  114. }