123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import '../index.dart';
- /// 设备检测按钮
- class DetectButton extends GetView<HardwareDetectionController> {
- DetectButton({
- Key? key,
- required this.deviceType,
- this.subTitleRowHright = 30.0,
- }) : super(key: key);
- final HardwareDeviceType deviceType;
- /// 副标题行高:[是否能看到画面变化]
- final double subTitleRowHright;
- /// 检测按钮文案
- String get detectButtonText {
- switch (deviceType) {
- case HardwareDeviceType.camera:
- return "测试摄像头";
- // return "i18nBook.setting.cameraTest.t";
- case HardwareDeviceType.speaker:
- return "测试扬声器";
- // return "i18nBook.setting.speakerTest.t";
- case HardwareDeviceType.microphone:
- return "测试麦克风";
- // return "i18nBook.setting.micTest.t";
- default:
- return "";
- }
- }
- /// 检测中询问文案
- String get detectingAskText {
- switch (deviceType) {
- case HardwareDeviceType.camera:
- return "XXXXXX?";
- case HardwareDeviceType.speaker:
- return "XXXXXX?";
- case HardwareDeviceType.microphone:
- return "XXXXXX?";
- default:
- return "";
- }
- }
- List<HardwareDevice> 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 Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- height: subTitleRowHright,
- child: Center(
- child: Text(
- detectingAskText,
- style: TextStyle(fontSize: 14, height: 1),
- ),
- ),
- ),
- Row(
- children: [
- InkWell(
- child: Container(
- padding:
- EdgeInsets.symmetric(horizontal: 15, vertical: 5),
- decoration: BoxDecoration(
- border: Border.all(color: Colors.green, width: 2),
- borderRadius: BorderRadius.circular(5),
- ),
- child: Text(
- "YES",
- style: TextStyle(
- fontSize: 14, color: Colors.green, height: 1),
- ),
- ),
- onTap: () {
- setDeviceAvailable(true);
- },
- ),
- SizedBox(
- width: 5,
- ),
- InkWell(
- child: Container(
- padding:
- EdgeInsets.symmetric(horizontal: 15, vertical: 5),
- decoration: BoxDecoration(
- border: Border.all(color: Colors.red, width: 2),
- borderRadius: BorderRadius.circular(5),
- ),
- child: Text(
- "NO",
- style: TextStyle(
- fontSize: 14, color: Colors.red, height: 1),
- ),
- ),
- onTap: () {
- setDeviceAvailable(false);
- },
- ),
- ],
- ),
- ],
- );
- } else {
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(
- height: subTitleRowHright,
- ),
- ElevatedButton(
- child: Text(
- detectButtonText,
- style:
- TextStyle(fontSize: 14, color: Colors.white, height: 1),
- ),
- onPressed: () {
- startDetectDevice();
- },
- ),
- ],
- );
- }
- },
- );
- }
- }
|