speaker_detection.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../index.dart';
  4. import 'widgets.dart';
  5. /// 扬声器检测
  6. class SpeakerDetection extends GetView<HardwareDetectionController> {
  7. SpeakerDetection({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. height: _subTitleRowHright,
  26. width: 300,
  27. child: Row(
  28. children: [
  29. Text("扬声器", style: smallTitleStyle),
  30. SizedBox(width: 10),
  31. Obx(() {
  32. if (controller.state.speakerAvailable == null)
  33. return Container();
  34. return controller.state.speakerAvailable!
  35. ? CommonWidgets.deviceAvailableTip()
  36. : CommonWidgets.deviceUnavailableTip();
  37. }),
  38. Expanded(child: Container()),
  39. InkWell(
  40. onTap: controller.refreshSpeakerList,
  41. child: Icon(
  42. Icons.refresh,
  43. size: 18,
  44. ),
  45. )
  46. ],
  47. ),
  48. ),
  49. _speakerSelector(),
  50. ],
  51. ),
  52. DetectButton(
  53. deviceType: HardwareDeviceType.speaker,
  54. subTitleRowHright: _subTitleRowHright,
  55. ),
  56. ],
  57. ),
  58. );
  59. }
  60. /// 扬声器选择器
  61. Widget _speakerSelector() {
  62. return Obx(
  63. () {
  64. List<HardwareDevice> source = controller.state.speakerList;
  65. bool noSpeaker = source.isEmpty;
  66. if (controller.state.searchingSpeaker)
  67. return CommonWidgets.deviceFindingTip();
  68. return noSpeaker
  69. ? CommonWidgets.deviceNotFoundTip()
  70. : Container(
  71. height: 30,
  72. width: 300,
  73. child: Row(
  74. children: [
  75. Expanded(
  76. child: Tooltip(
  77. message: "${source.first.name}",
  78. child: Center(
  79. child: Text(
  80. source.first.name,
  81. style: TextStyle(
  82. fontSize: 14,
  83. color: Colors.black,
  84. ),
  85. overflow: TextOverflow.ellipsis,
  86. ),
  87. ),
  88. ),
  89. ),
  90. ],
  91. ),
  92. );
  93. },
  94. );
  95. }
  96. }