import 'package:flutter/material.dart'; import 'package:fis_ui/index.dart'; import 'package:fis_ui/base_define/page.dart'; import 'package:get/get.dart'; import '../index.dart'; /// 设备检测按钮 class DetectButton extends GetView implements FPage { DetectButton({ Key? key, required this.deviceType, this.subTitleRowHright = 30.0, }) : super(key: key); @override String get pageName => "detect_button"; final HardwareDeviceType deviceType; /// 副标题行高:[是否能看到画面变化] final double subTitleRowHright; /// 检测按钮文案 String get detectButtonText { switch (deviceType) { case HardwareDeviceType.camera: return "检测摄像头"; case HardwareDeviceType.speaker: return "检测扬声器"; case HardwareDeviceType.microphone: return "检测麦克风"; default: return ""; } } /// 检测中询问文案 String get detectingAskText { switch (deviceType) { case HardwareDeviceType.camera: return "是否能看到画面?"; case HardwareDeviceType.speaker: return "是否能听到音乐?"; case HardwareDeviceType.microphone: return "是否能看到音量条变化?"; default: return ""; } } List get deviceList { switch (deviceType) { case HardwareDeviceType.camera: return controller.state.cameraList; case HardwareDeviceType.speaker: return controller.state.speakerList; case HardwareDeviceType.microphone: return controller.state.microphoneList; default: return []; } } bool get detectingDevice { switch (deviceType) { case HardwareDeviceType.camera: return controller.state.detectingCamera; case HardwareDeviceType.speaker: return controller.state.detectingSpeaker; case HardwareDeviceType.microphone: return controller.state.detectingMicrophone; default: return false; } } Function get setDeviceAvailable { switch (deviceType) { case HardwareDeviceType.camera: return controller.setCameraAvailable; case HardwareDeviceType.speaker: return controller.setSpeakerAvailable; case HardwareDeviceType.microphone: return controller.setMicrophoneAvailable; default: return () {}; } } Function get startDetectDevice { switch (deviceType) { case HardwareDeviceType.camera: return controller.startDetectingCamera; case HardwareDeviceType.speaker: return controller.startDetectingSpeaker; case HardwareDeviceType.microphone: return controller.startDetectingMicrophone; default: return () {}; } } @override Widget build(BuildContext context) { return Obx( () { bool noDevice = deviceList.isEmpty; bool isDetectingDevice = detectingDevice; if (noDevice) return Container(); if (isDetectingDevice) { return FColumn( crossAxisAlignment: CrossAxisAlignment.start, children: [ FContainer( height: subTitleRowHright, child: FCenter( child: FText( detectingAskText, style: TextStyle(fontSize: 14, height: 1), ), ), ), FRow( children: [ FInkWell( child: Container( padding: EdgeInsets.symmetric(horizontal: 15, vertical: 5), decoration: BoxDecoration( border: Border.all(color: Colors.green, width: 2), borderRadius: BorderRadius.circular(5), ), child: FText( "是", style: TextStyle( fontSize: 14, color: Colors.green, height: 1), ), ), onTap: () { setDeviceAvailable(true); }, ), FSizedBox( width: 5, ), FInkWell( child: Container( padding: EdgeInsets.symmetric(horizontal: 15, vertical: 5), decoration: BoxDecoration( border: Border.all(color: Colors.red, width: 2), borderRadius: BorderRadius.circular(5), ), child: FText( "否", style: TextStyle( fontSize: 14, color: Colors.red, height: 1), ), ), onTap: () { setDeviceAvailable(false); }, ), ], ), ], ); } else { return FColumn( crossAxisAlignment: CrossAxisAlignment.start, children: [ FSizedBox( height: subTitleRowHright, ), /// FIXME 检测摄像头按钮 [外部无法直接使用 FElevatedButton,因为获取不到全局 env 参数] // FElevatedButton( // businessParent: this, // name: "startDetectingCamera", // child: FText(detectButtonText), // onPressed: () { // startDetectDevice(); // }, // ), FInkWell( child: FText( detectButtonText, style: TextStyle(fontSize: 14, color: Colors.blue, height: 1), ), onTap: () { startDetectDevice(); }, ), ], ); } }, ); } }