import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/scheduler.dart';
import 'dart:math';
import 'dart:async';
import 'package:path_provider/path_provider.dart';
import 'package:percent_indicator/percent_indicator.dart';
import 'package:flutter/services.dart';
import 'package:gme_flutter/tmg_sdk.dart';
import 'package:gme_flutter/tmg_type.dart';
import 'package:gme_flutter/tmg_audio_effect_ctrl.dart';
import 'updateSelfDialog.dart';
import 'package:permission_handler/permission_handler.dart';

class RealVoicePage extends StatefulWidget {
  RealVoicePage({Key? key}) : super(key: key);

  @override
  _RealVoicePageState createState() {
    return _RealVoicePageState();
  }
}

class MyCallback implements ITMGDelegate {
  @override
  void onEvent(int event_type, String data) {
    _RealVoicePageInstance.handleEventMsg(event_type, data);
    eventHandler(event_type, data);
  }

  static MyCallback? _instance;
  static MyCallback getInstance() {
    if (_instance == null) {
      _instance = MyCallback();
    }
    return _instance!;
  }

  void Function(int, String) eventHandler = (int, String) {};
  late _RealVoicePageState _RealVoicePageInstance;
}

class _RealVoicePageState extends State<RealVoicePage>
    with WidgetsBindingObserver {
  @override
  void initState() {
    WidgetsBinding.instance!.addObserver(this);
    super.initState();
    initAccompyState();
    initRealVoice();
  }

  void initRealVoice() async {
    final pathObj = await getApplicationDocumentsDirectory();
    _curFilePath = pathObj.path;
  }

  void dispose() {
    WidgetsBinding.instance!.removeObserver(this);
    super.dispose();
  }

  _showToast(String msg) {
    return;
    // Widget toast = Container(
    //   padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
    //   decoration: BoxDecoration(
    //     borderRadius: BorderRadius.circular(25.0),
    //     color: Colors.greenAccent,
    //   ),
    //   child: Row(
    //     mainAxisSize: MainAxisSize.min,
    //     children: [
    //       Icon(Icons.check),
    //       SizedBox(
    //         width: 12.0,
    //       ),
    //       Text(msg),
    //     ],
    //   ),
    // );

    // fToast?.showToast(
    //   child: toast,
    //   gravity: ToastGravity.BOTTOM,
    //   toastDuration: Duration(seconds: 2),
    // );

    // // Custom Toast Position
    // fToast?.showToast(
    //     child: toast,
    //     toastDuration: Duration(seconds: 2),
    //     positionedToastBuilder: (context, child) {
    //       return Positioned(
    //         child: child,
    //         top: 16.0,
    //         left: 16.0,
    //       );
    //     });
  }

  void didChangeAppLifecycleState(AppLifecycleState state) {
    print('didChangeAppLifecycleState ' + state.toString());
    switch (state) {
      case AppLifecycleState.inactive:
        {
          ITMGContext.GetInstance().Pause();
        } // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。
        break;
      case AppLifecycleState.resumed:
        {
          ITMGContext.GetInstance().Resume();
        } //从后台切换前台，界面可见
        break;
      case AppLifecycleState.paused:
        {
          ITMGContext.GetInstance().Pause();
          break;
        }
      case AppLifecycleState.detached: // APP结束时调用
        break;
      default:
        break;
    }
  }

  void showUpdateSelfParamPicker() {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return StatefulBuilder(
          builder: (context, StateSetter setState) {
            return UpdateSelfDialogPage();
          },
        );
      },
    );
  }

  void showCupertinoAlertDialog(String strTitle, String strBody) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return CupertinoAlertDialog(
          title: Text("$strTitle"),
          content: Column(
            children: <Widget>[
              SizedBox(height: 10),
              Align(child: Text("$strBody"), alignment: Alignment(0, 0)),
            ],
          ),
          actions: <Widget>[
            CupertinoDialogAction(
              child: Text("ok"),
              onPressed: () {
                Navigator.pop(context);
              },
            ),
          ],
        );
      },
    );
  }

  bool _switchInitGmeSDK = false; //维护单选开关状态
  bool _switchEnterRoom = false;
  bool _switchMic = false;
  bool _switchSpk = false;
  bool _switchCapture = false;
  bool _switchSend = false;
  bool _switchPlay = false;
  bool _switchRecv = false;
  bool _switchLoopback = false;
  bool _switchReleaseAudioFoucus = false;
  bool _switchRoomSharing = false;
  bool _switchSendCustomData = false;
  bool _switchChorusWithOpenID = false;
  bool _switchChorusVocalAccompaniment = false;
  bool _switchEnableSpatializer = false;
  bool _switchTrackingVolume = false;
  ITMGRoomType _curRoomType = ITMGRoomType.ITMG_ROOM_TYPE_FLUENCY;
  int _curLogLevel = 4;
  ITMG_RANGE_AUDIO_MODE _curRangeMode =
      ITMG_RANGE_AUDIO_MODE.ITMG_RANGE_AUDIO_MODE_SND_BOTH_REC_BOTH;
  ITMG_APP_SCENE _curAppScene = ITMG_APP_SCENE.ITMG_APP_SCENE_RTC;
  ITMG_AUDIO_MEMBER_ROLE _curMemberRole =
      ITMG_AUDIO_MEMBER_ROLE.ITMG_AUDIO_MEMBER_ROLE_ANCHOR;
  double _curRangeSize = 1.0;
  int _selectedVoice = 0;
  int _iAgeDetected = 0;
  int _otherGetSpkVol = 0;
  int _curStreamLevel = 0;
  int _curMicLevel = 0;
  int _curSpeakerLevel = 0;
  int _micVolume = 0;
  int _spkVolume = 0;
  int _curSendStreamLevel = 0;
  int _curRecvStreamLevel = 0;
  int _roomType = 0;
  bool _enable_capture = false;
  bool _enableAudioSend = false;
  bool _enable_recv = false;
  bool _inBlacklist = false;
  double _micValue = 100;
  double _spkValue = 100;
  double _otherSpkVolume = 100;
  Timer? _pollTimer;

  String _callbackMessage = 'callBackMassage';
  String _sdkVersions = "";
  String _curFilePath = "";
  String _curLogPath = "Doument";
  String _strInRooms = "InRoom";
  String _curMicPermission = "NotDetermined";
  String _curAdvanceValue = "Advance";
  String _checkMicState = "checkMic";
  String _advanceParams = "DisableEncryptLog";
  String _curRegion = "DEFAULT";
  bool _roomMangaerOpen = false;

  bool _roomMicState = false;
  bool _roomSpkState = false;
  bool _roomSend = false;
  bool _roomRecv = false;
  bool _roomCapture = false;
  bool _roomPlay = false;
  bool _roomUserForbid = false;
  bool _roomUserBlock = false;
  bool _isEnableSpatializer = false;
  bool _switchPlayMusic = false;
  bool _pausePlayMusic = false;
  Set<String> _roomMembers = Set<String>();
  String? authBuffer = null;
  String _curRoomID = "";
  String _recordFilePath = "";
  String _accompyFileDir = "";
  List<String> _accompyFilePaths = [];
  String _strMusicPlayEnd = "MusicIsPlayEnd";
  double _musicPublishVolume = 0.0;
  int _nMusicPublishVolume = 0;
  double _musicPlayoutVolume = 0.0;
  int _nMusicPlayoutVolume = 0;
  double _allMusicVolume = 0.0;
  double _musicPitch = 0.0;
  Timer? _progressTime;
  int _musicSoundID = 0;
  Duration _accompySchedule = Duration.zero;
  Duration _accompyLens = Duration.zero;
  bool _switchEnableMusicPublish = true;
  bool _switchEnableMusicPlayout = true;
  ITMG_VOICE_TYPE _nVoiceType = ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_ORIGINAL_SOUND;
  ITMG_KARAOKE_TYPE _nKaraokeType = ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_0;
  ITMG_AUDIO_RECORDING_CONTENT _nRecordingType =
      ITMG_AUDIO_RECORDING_CONTENT.ITMG_AUDIO_RECORDING_CONTENT_ALL;
  bool _switchRecordStart = false;

  final _editAppID = TextEditingController(text: AppID To Replace Here https://cloud.tencent.com/document/product/607/10782);
  final _editKey = TextEditingController(
    text: AppKey To Replace Here https://cloud.tencent.com/document/product/607/10782,
  );
  final _editRoomID = TextEditingController(text: '20250101');
  final _editOpenID = TextEditingController(text: '');
  final _editAdvanceParamsID = TextEditingController(
    text: 'DisableEncryptLog:1',
  );
  final _editTeamID = TextEditingController(text: '');
  final _editRecvMixStreamCount = TextEditingController(text: '');
  final _editRoomManagerID = TextEditingController(text: '');
  final _editOtherRoomID = TextEditingController(text: '20220102');
  final _editOtherOpenID = TextEditingController(text: '');
  final _editcustomDataID = TextEditingController(text: 'send msg');
  final _editcustomRepeatCountID = TextEditingController(text: '1');
  final _editUpdateSpatializerRecvRangeID = TextEditingController(text: '1.0');
  final _editMusicNameID = TextEditingController(text: '222.mp3');
  final _editMusicID = TextEditingController(text: '0');
  final _editMusicPlayCountID = TextEditingController(text: '-1');

  //FToast? fToast = null;
  _RealVoicePageState() {
    _editOpenID.text = (10000 + Random().nextInt(1000)).toString();
    _editTeamID.text = (10000 + Random().nextInt(1000)).toString();
    _editRecvMixStreamCount.text = '2';
    _editUpdateSpatializerRecvRangeID.text = '1.0';
  }
  Future<void> pollTimer() async {
    _pollTimer = Timer.periodic(Duration(milliseconds: 500), (Timer timer) {
      ITMGContext.GetInstance().Poll();
    });
  }

  Future<void> enterRoom(bool isCheck) async {
    if (isCheck) {
      authBuffer = await ITMGContext.GetInstance().GenAuthBuffer(
        int.parse(_editAppID.text),
        _editRoomID.text,
        _editOpenID.text,
        _editKey.text,
      );
      int res = await ITMGContext.GetInstance().EnterRoom(
        _editRoomID.text,
        _curRoomType,
        authBuffer!,
      );
      if (res != 0) {
        showCupertinoAlertDialog(
          "Invalid operation",
          "Please check the error code $res",
        );
        return;
      }
    } else {
      // ignore: avoid_print
      ITMGContext.GetInstance().ExitRoom();
      print('switch close');
    }
  }

  void initGmeSDK(bool isCheck) async {
    if (isCheck != false) {
      authBuffer = await ITMGContext.GetInstance().GenAuthBuffer(
        int.parse(_editAppID.text),
        _editRoomID.text,
        _editOpenID.text,
        _editKey.text,
      );

      int res = await ITMGContext.GetInstance().Init(
        _editAppID.text,
        _editOpenID.text,
      );
      if (res != 0) {
        showCupertinoAlertDialog(
          "Invalid operation",
          "int error, Please check the error code $res",
        );
        return;
      }

      res = await ITMGContext.GetInstance().GetPTT().ApplyPTTAuthbuffer(
        authBuffer!,
      );
      if (res != 0) {
        showCupertinoAlertDialog(
          "Invalid operation",
          "ApplyPTTAuthbuffer error, Please check the error code $res",
        );
        return;
      }

      _sdkVersions = await ITMGContext.GetInstance().GetSDKVersion();
      String appVersion = 'gme_flutter_plugin_version: ' + _sdkVersions;
      ITMGContext.GetInstance().SetAppVersion(appVersion);
      MyCallback.getInstance()._RealVoicePageInstance = this;
      ITMGContext.GetInstance().SetTMGDelegate(MyCallback.getInstance());
      pollTimer();
      // ignore: avoid_print
    } else {
      // ignore: avoid_print
      ITMGContext.GetInstance().Uninit();
      _pollTimer!.cancel();
      setState(() {
        _switchEnterRoom = false;
        _switchMic = false;
        _switchLoopback = false;
        _switchSpk = false;
        _sdkVersions = "";
        _curRoomID = "";
      });
    }
    setState(() {
      _switchInitGmeSDK = isCheck;
    });
  }

  Future<void> SendCustomData(bool value) async {
    int res = 0;
    if (value) {
      res = await ITMGContext.GetInstance().GetRoom().SendCustomData(
        stringToUint8List(_editcustomDataID.text),
        int.parse(_editcustomRepeatCountID.text),
      );
    } else {
      res = await ITMGContext.GetInstance().GetRoom().StopSendCustomData();
    }
    setState(() {
      _switchSendCustomData = value;
    });
    if (res != 0) {
      showCupertinoAlertDialog(
        "Invalid operation",
        "Please check the error code $res",
      );
      return;
    }
  }

  void handleEventMsg(int eventType, String data) async {
    // print('yxh----------------Event received:');
    // print('yxh-----  event_type: $eventType');
    // print('yxh--------  data: ${data}');
    switch (eventType) {
      case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ENTER_ROOM:
        {
          setState(() {
            _switchEnterRoom = true;
          });
        }
        break;
      case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_EXIT_ROOM:
        {
          setState(() {
            _switchEnterRoom = false;
            _switchMic = false;
            _switchSpk = false;
            _switchCapture = false;
            _switchSend = false;
            _switchRecv = false;
            _switchPlay = false;
            _switchLoopback = false;
            _roomUserBlock = false;
            _curRoomID = "";
          });
          UpdateSelfDialogPage.ClearUserIdList();
        }
        break;
      case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_USER_UPDATE:
        {
          var dataJson = json.decode(data);
          int updataEvent = dataJson['event_id'];
          var members = dataJson['user_list'];
          if (ITMG_EVENT_ID_USER_UPDATE.ITMG_EVENT_ID_USER_ENTER.value ==
              updataEvent) {
            for (String curMember in members) {
              if (_editOpenID.text == curMember) {
                curMember = "mySelf";
              }
              _roomMembers.add(curMember);
              UpdateSelfDialogPage.AddUserId(curMember);
            }
          } else if (ITMG_EVENT_ID_USER_UPDATE.ITMG_EVENT_ID_USER_EXIT.value ==
              updataEvent) {
            for (String curMember in members) {
              if (_editOpenID.text == curMember) {
                curMember = "mySelf";
              }
              _roomMembers.remove(curMember);
              UpdateSelfDialogPage.RemoveUserId(curMember);
            }
          }
        }
        break;
      case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ROOM_DISCONNECT:
        {
          // 处理房间断开连接事件
          setState(() {
            _switchEnterRoom = false;
            _switchMic = false;
            _switchSpk = false;
          });
        }
        break;
      case ITMG_MAIN_EVENT_TYPE.ITMG_MAIN_EVENT_TYPE_ROOM_MANAGEMENT_OPERATOR:
        {
          // 处理房间管理操作事件
        }
        break;
      default:
        break;
    }
    setState(() {
        _callbackMessage = 'eventType: ' + eventType.toString() + '; data: ' + data;
    });
  }

  void changeMicState(bool isCheck) async {
    int res = await ITMGContext.GetInstance().GetAudioCtrl().EnableMic(isCheck);
    print("MicState == " + res.toString());
    if (res != 0) {
      showCupertinoAlertDialog(
        "Operation Failed",
        "Unable to operate the microphone, please check the error code $res",
      );
      return;
    }
    changeCaptureState(isCheck);
    changeSendState(isCheck);
    setState(() {
      _switchMic = isCheck;
    });
  }

  void changeSpkState(bool isCheck) async {
    int res = await ITMGContext.GetInstance().GetAudioCtrl().EnableSpeaker(
      isCheck,
    );
    if (res != 0) {
      showCupertinoAlertDialog(
        "Operation Failed",
        "Unable to operate the speaker, please check the error code $res",
      );
      return;
    }
    changeRecvState(isCheck);
    changePlayState(isCheck);
    setState(() {
      _switchSpk = isCheck;
    });
  }

  void changeCaptureState(bool isCheck) async {
    if ((Platform.isAndroid || Platform.operatingSystem == 'ohos') && isCheck) {
      bool status = await Permission.microphone.isGranted;
      if (!status) {
        await Permission.microphone.request().isGranted;
      }
    }
    int res = await ITMGContext.GetInstance()
        .GetAudioCtrl()
        .EnableAudioCaptureDevice(isCheck);
    if (res != 0) {
      showCupertinoAlertDialog(
        "Operation Failed",
        "Unable to operate the CaptureDevice, please check the error code $res",
      );
      return;
    }
    int micState = ITMGContext.GetInstance().GetAudioCtrl().GetMicState();
    setState(() {
      _switchCapture = isCheck;
      if (micState != 0) {
        _switchMic = true;
      } else {
        _switchMic = false;
      }
    });
  }

  void changeSendState(bool isCheck) async {
    int res = await ITMGContext.GetInstance().GetAudioCtrl().EnableAudioSend(
      isCheck,
    );
    if (res != 0) {
      showCupertinoAlertDialog(
        "Operation Failed",
        "Unable to operate the EnableAudioSend, please check the error code $res",
      );
      return;
    }
    int micState = ITMGContext.GetInstance().GetAudioCtrl().GetMicState();
    setState(() {
      _switchSend = isCheck;
      if (micState != 0) {
        _switchMic = true;
      } else {
        _switchMic = false;
      }
    });
  }

  void changePlayState(bool isCheck) async {
    int res = await ITMGContext.GetInstance()
        .GetAudioCtrl()
        .EnableAudioPlayDevice(isCheck);
    if (res != 0) {
      showCupertinoAlertDialog(
        "Operation Failed",
        "Unable to operate the AudioPlayDevice, please check the error code $res",
      );
      return;
    }
    int speakerState =
        ITMGContext.GetInstance().GetAudioCtrl().GetSpeakerState();
    setState(() {
      _switchPlay = isCheck;
      if (speakerState != 0) {
        _switchSpk = true;
      } else {
        _switchSpk = false;
      }
    });
  }

  void changeRecvState(bool isCheck) async {
    int res = await ITMGContext.GetInstance().GetAudioCtrl().EnableAudioRecv(
      isCheck,
    );
    if (res != 0) {
      showCupertinoAlertDialog(
        "Operation Failed",
        "Unable to operate the AudioRecv, please check the error code $res",
      );
      return;
    }
    int speakerState =
        ITMGContext.GetInstance().GetAudioCtrl().GetSpeakerState();
    setState(() {
      _switchRecv = isCheck;
      if (speakerState != 0) {
        _switchSpk = true;
      } else {
        _switchSpk = false;
      }
    });
  }

  void changeLoopbackState(bool isCheck) async {
    int res = await ITMGContext.GetInstance().GetAudioCtrl().EnableLoopBack(
      isCheck,
    );
    print("LoopState == " + res.toString());
    setState(() {
      _switchLoopback = isCheck;
    });
  }

  void OnEnableSpatializer(bool isCheck) async {
    int res = await ITMGContext.GetInstance().GetAudioCtrl().EnableSpatializer(
      isCheck,
    );
    if (res != 0) {
      showCupertinoAlertDialog(
        "Operation Failed",
        "Unable to operate EnableSpatializer, please check the error code $res",
      );
      return;
    }
    setState(() {
      _switchEnableSpatializer = isCheck;
    });
  }

  Future<String> copyAssets(String filePath) async {
    final pathObj = await getApplicationDocumentsDirectory();
    String curPath = pathObj.path;
    _accompyFileDir = curPath;
    _accompyFileDir += "/";
    curPath = curPath + filePath;
    File accompfile = File('$curPath');
    bool isExist = await accompfile.exists();
    if (!isExist) {
      ByteData bytes = await rootBundle.load('assets$filePath');
      accompfile.writeAsBytes(
        bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes),
      );
    }
    return curPath;
  }

  void initAccompyState() async {
    final pathObj = await getApplicationDocumentsDirectory();
    String curPath = pathObj.path;
    _recordFilePath = curPath + "/record.aac";
    String curFilePath = await copyAssets("/333.m4a");
    _accompyFilePaths.add(curFilePath);
    curFilePath = await copyAssets("/444.wav");
    _accompyFilePaths.add(curFilePath);
    curFilePath = await copyAssets("/555.aac");
    _accompyFilePaths.add(curFilePath);
    curFilePath = await copyAssets("/222.mp3");
    _accompyFilePaths.add(curFilePath);
  }

  Future<void> progressTimer() async {
    _progressTime = Timer.periodic(Duration(seconds: 1), (timer) async {
      int currentMusicId = int.parse(_editMusicID.text);
      int res = ITMGContext.GetInstance()
          .GetAudioEffectCtrl()
          .GetMusicDurationInMS(currentMusicId);
      _accompyLens = Duration(milliseconds: res);

      res = await ITMGContext.GetInstance()
          .GetAudioEffectCtrl()
          .GetMusicCurrentPosInMS(currentMusicId);
      bool flagEnd = await ITMGContext.GetInstance()
          .GetAudioEffectCtrl()
          .IsMusicPlayEnd(currentMusicId);
      setState(() {
        _accompySchedule = Duration(milliseconds: res);
      });
    });
  }

  void SetAdvance() {
    String advanceParams = _editAdvanceParamsID.text;
    advanceParams = advanceParams.replaceAll('\r', '').replaceAll('\n', '');
    List<String> advParams = advanceParams.split(';');

    for (String param in advParams) {
      if (param.isEmpty) {
        continue;
      }

      debugPrint("SetAdvParam: $param");
      List<String> kv = param.split(':');

      if (kv.length != 2) {
        continue;
      }
      ITMGContext.GetInstance().SetAdvanceParams(kv[0], kv[1]);
    }
  }

  void GetAdvanceParams() {
    String advanceKey = _editAdvanceParamsID.text;
    String advanceParams = ITMGContext.GetInstance().GetAdvanceParams(
      advanceKey,
    );
    if (advanceParams.isEmpty) {
      showCupertinoAlertDialog(
        "Invalid operation",
        "GetAdvanceParams $advanceKey is empty",
      );
      return;
    }
    _editAdvanceParamsID.text = advanceParams;
  }

  Uint8List stringToUint8List(String input) {
    List<int> codeUnits = utf8.encode(input);
    return Uint8List.fromList(codeUnits);
  }

  Widget build(BuildContext context) {
    return SingleChildScrollView(
      scrollDirection: Axis.vertical,
      reverse: false,
      controller: ScrollController(),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(""),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextField(
                controller: _editAppID,
                decoration: const InputDecoration(
                  icon: Icon(Icons.app_blocking),
                  labelText: 'AppID',
                  labelStyle: TextStyle(color: Colors.blueGrey, fontSize: 20),
                  enabledBorder: OutlineInputBorder(
                    /*边角*/
                    borderRadius: BorderRadius.all(
                      Radius.circular(30), //边角为30
                    ),
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边线颜色为黄色
                      width: 2, //边线宽度为2
                    ),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边框颜色为绿色
                      width: 2, //宽度为5
                    ),
                  ),
                ),
              ),
              const Text(""),
              TextField(
                controller: _editKey,
                obscureText: true,
                decoration: const InputDecoration(
                  icon: Icon(Icons.password_sharp),
                  labelText: 'AppKey',
                  hintMaxLines: 100,
                  labelStyle: TextStyle(color: Colors.blueGrey, fontSize: 20),
                  enabledBorder: OutlineInputBorder(
                    /*边角*/
                    borderRadius: BorderRadius.all(
                      Radius.circular(30), //边角为30
                    ),
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边线颜色为黄色
                      width: 2, //边线宽度为2
                    ),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边框颜色为绿色
                      width: 2, //宽度为5
                    ),
                  ),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  DropdownButton<String>(
                    items: [
                      DropdownMenuItem(
                        child: Text(
                          'DEFAULT',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: "DEFAULT",
                      ),
                      DropdownMenuItem(
                        child: Text(
                          'DEFAULT_TEST',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: 'DEFAULT_TEST',
                      ),
                      DropdownMenuItem(
                        child: Text(
                          'SG_GLOBAL',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: 'SG_GLOBAL',
                      ),
                      DropdownMenuItem(
                        child: Text(
                          'SG_GLOBAL_TEST',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: 'SG_GLOBAL_TEST',
                      ),
                      DropdownMenuItem(
                        child: Text(
                          'CHN',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: 'REGION_CHN',
                      ),
                      DropdownMenuItem(
                        child: Text(
                          'CHN_TEST',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: 'REGION_CHN_TEST',
                      ),
                      DropdownMenuItem(
                        child: Text(
                          'INTERNATIONAL',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: 'REGION_INTERNATIONAL',
                      ),
                      DropdownMenuItem(
                        child: Text(
                          'INTERNATIONAL_TEST',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: 'REGION_INTERNATIONAL_TEST',
                      ),
                    ],
                    value: _curRegion,
                    icon: Icon(Icons.location_on),
                    onChanged: (String? value) {
                      if (value != null) {
                        ITMGContext.GetInstance().SetRegion(value);
                        setState(() {
                          _curRegion = value;
                        });
                      }
                    },
                  ),
                  DropdownButton<ITMG_APP_SCENE>(
                    items: [
                      DropdownMenuItem(
                        child: Text(
                          'SCENE_RTC',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_APP_SCENE.ITMG_APP_SCENE_RTC,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          'SCENE_LIVE',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_APP_SCENE.ITMG_APP_SCENE_LIVE,
                      ),
                    ],
                    value: _curAppScene,
                    icon: Icon(Icons.person_outlined),
                    onChanged: (ITMG_APP_SCENE? value) {
                      if (value != null) {
                        ITMGContext.GetInstance().SetScene(value);
                        setState(() {
                          _curAppScene = value;
                        });
                      }
                    },
                  ),
                ],
              ),

              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  DropdownButton<ITMG_AUDIO_MEMBER_ROLE>(
                    items: [
                      DropdownMenuItem(
                        child: Text(
                          'ROLE_ANCHOR',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value:
                            ITMG_AUDIO_MEMBER_ROLE
                                .ITMG_AUDIO_MEMBER_ROLE_ANCHOR,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          'ROLE_AUDIENCE',
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value:
                            ITMG_AUDIO_MEMBER_ROLE
                                .ITMG_AUDIO_MEMBER_ROLE_AUDIENCE,
                      ),
                    ],
                    value: _curMemberRole,
                    icon: Icon(Icons.person),
                    onChanged: (ITMG_AUDIO_MEMBER_ROLE? value) {
                      if (value != null) {
                        ITMGContext.GetInstance().SetAudioRole(value);
                        setState(() {
                          _curMemberRole = value;
                        });
                      }
                    },
                  ),
                ],
              ),
              const Text(""),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Expanded(
                    child: TextField(
                      controller: _editRoomID,
                      decoration: const InputDecoration(
                        icon: Icon(Icons.home_filled),
                        labelText: 'RoomID',
                        hintMaxLines: 100,
                        labelStyle: TextStyle(
                          color: Colors.blueGrey,
                          fontSize: 20,
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(30)),
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                      ),
                    ),
                  ),
                  const SizedBox(width: 10),
                  Expanded(
                    child: TextField(
                      controller: _editOpenID,
                      decoration: const InputDecoration(
                        icon: Icon(Icons.person),
                        labelText: 'OpenID',
                        hintMaxLines: 100,
                        labelStyle: TextStyle(
                          color: Colors.blueGrey,
                          fontSize: 20,
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(30)),
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'InitSDK',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(value: _switchInitGmeSDK, onChanged: initGmeSDK),
                  Text(
                    'EnterRoom',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(value: _switchEnterRoom, onChanged: enterRoom),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  TextButton.icon(
                    onPressed: () async {
                      String res =
                          ITMGContext.GetInstance().GetRoom().GetRoomID();
                      setState(() {
                        _curRoomID = res;
                      });
                    },
                    icon: Icon(Icons.house),
                    label: Text("GetRoomID:$_curRoomID"),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'MicState',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(value: _switchMic, onChanged: changeMicState),
                  Text(
                    'SpkState',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(value: _switchSpk, onChanged: changeSpkState),
                  TextButton.icon(
                    onPressed: () async {
                      bool res =
                          await ITMGContext.GetInstance().IsRoomEntered();
                      setState(() {
                        if (res) {
                          _strInRooms = "Yes";
                        } else {
                          _strInRooms = "Not";
                        }
                      });
                    },
                    icon: Icon(Icons.room_outlined),
                    label: Text("$_strInRooms"),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text("Cap", style: Theme.of(context).textTheme.labelLarge),
                  Switch(value: _switchCapture, onChanged: changeCaptureState),
                  Text("Send", style: Theme.of(context).textTheme.labelLarge),
                  Switch(value: _switchSend, onChanged: changeSendState),
                  Text("Play", style: Theme.of(context).textTheme.labelLarge),
                  Switch(value: _switchPlay, onChanged: changePlayState),
                  Text("Recv", style: Theme.of(context).textTheme.labelLarge),
                  Switch(value: _switchRecv, onChanged: changeRecvState),
                ],
              ),
              Row(
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      final int res =
                          await ITMGContext.GetInstance()
                              .GetAudioCtrl()
                              .GetMicVolume();
                      setState(() {
                        _micVolume = res;
                      });
                    },
                    icon: Icon(Icons.mic_sharp),
                    label: Text("MicV:$_micVolume"),
                  ),
                  Slider(
                    value: _micValue,
                    activeColor: Colors.blueGrey,
                    inactiveColor: Colors.grey,
                    label: 'micValue:$_micValue',
                    min: 0,
                    max: 200,
                    divisions: 50,
                    onChangeEnd: (value) async {
                      int volume = value.toInt();
                      int res = await ITMGContext.GetInstance()
                          .GetAudioCtrl()
                          .SetMicVolume(volume);
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      }
                    },
                    onChanged: (value) {
                      setState(() {
                        int curValue = value.toInt();
                        _micValue = curValue.toDouble();
                      });
                    },
                  ),
                ],
                mainAxisAlignment: MainAxisAlignment.center,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      final int res =
                          await ITMGContext.GetInstance()
                              .GetAudioCtrl()
                              .GetSpeakerVolume();
                      setState(() {
                        _spkVolume = res;
                      });
                    },
                    icon: Icon(Icons.mic_sharp),
                    label: Text("SpkV:$_spkVolume"),
                  ),
                  Slider(
                    value: _spkValue,
                    activeColor: Colors.blueGrey,
                    inactiveColor: Colors.grey,
                    label: 'spkValue:$_spkValue',
                    min: 0,
                    max: 200,
                    divisions: 50,
                    onChangeEnd: (value) async {
                      int volume = value.toInt();
                      int res = await ITMGContext.GetInstance()
                          .GetAudioCtrl()
                          .SetSpeakerVolume(volume);
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      }
                    },
                    onChanged: (value) {
                      setState(() {
                        int curValue = value.toInt();
                        _spkValue = curValue.toDouble();
                      });
                    },
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'Loopback',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(
                    value: _switchLoopback,
                    onChanged: changeLoopbackState,
                  ),
                  DropdownButton<ITMGRoomType>(
                    items: [
                      DropdownMenuItem(
                        child: Text('Fluency'),
                        value: ITMGRoomType.ITMG_ROOM_TYPE_FLUENCY,
                      ),
                      DropdownMenuItem(
                        child: Text('Standard'),
                        value: ITMGRoomType.ITMG_ROOM_TYPE_STANDARD,
                      ),
                      DropdownMenuItem(
                        child: Text('HighQuality'),
                        value: ITMGRoomType.ITMG_ROOM_TYPE_HIGHQUALITY,
                      ),
                    ],
                    value: _curRoomType,
                    icon: Icon(Icons.high_quality_sharp),
                    onChanged: (value) async {
                      ITMGRoomType curRoomType = value!;
                      int res = await ITMGContext.GetInstance()
                          .GetRoom()
                          .ChangeRoomType(curRoomType);
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );

                        return;
                      }
                      setState(() {
                        if (value != null) {
                          _curRoomType = value;
                        }
                      });
                    },
                  ),
                ],
              ),
              TextField(
                controller: _editAdvanceParamsID,
                decoration: const InputDecoration(
                  icon: Icon(Icons.app_blocking),
                  labelText: 'advanceParamsOrKey',
                  labelStyle: TextStyle(color: Colors.blueGrey, fontSize: 20),
                  enabledBorder: OutlineInputBorder(
                    /*边角*/
                    borderRadius: BorderRadius.all(
                      Radius.circular(30), //边角为30
                    ),
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边线颜色为黄色
                      width: 2, //边线宽度为2
                    ),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边框颜色为绿色
                      width: 2, //宽度为5
                    ),
                  ),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  TextButton.icon(
                    label: Text("setAdvanceParams"),
                    onPressed: () async {
                      SetAdvance();
                    },
                    icon: Icon(Icons.update_sharp),
                  ),
                  TextButton.icon(
                    label: Text("getAdvanceParams"),
                    onPressed: () async {
                      GetAdvanceParams();
                    },
                    icon: Icon(Icons.update_sharp),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text(
                    'TrackingVolume',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(
                    value: _switchTrackingVolume,
                    onChanged: (value) async {
                      int res = 0;
                      if (value) {
                        res = await ITMGContext.GetInstance()
                            .GetAudioCtrl()
                            .TrackingVolume(2.0);
                      } else {
                        res =
                            await ITMGContext.GetInstance()
                                .GetAudioCtrl()
                                .StopTrackingVolume();
                      }
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      }
                      setState(() {
                        _switchTrackingVolume = value;
                      });
                    },
                  ),
                ],
              ),
              const Text(""),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Expanded(
                    child: TextField(
                      controller: _editTeamID,
                      decoration: const InputDecoration(
                        icon: Icon(Icons.ten_mp_sharp),
                        labelText: 'TeamID',
                        hintMaxLines: 100,
                        labelStyle: TextStyle(
                          color: Colors.blueGrey,
                          fontSize: 20,
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(30)),
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                      ),
                    ),
                  ),
                  const SizedBox(width: 10),
                  Expanded(
                    child: TextField(
                      controller: _editRecvMixStreamCount,
                      decoration: const InputDecoration(
                        icon: Icon(Icons.ten_mp_sharp),
                        labelText: 'RecvMixStreamCount',
                        hintMaxLines: 100,
                        labelStyle: TextStyle(
                          color: Colors.blueGrey,
                          fontSize: 20,
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(30)),
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ],
          ),
          const SizedBox(height: 20),
          TextField(
            controller: _editUpdateSpatializerRecvRangeID,
            decoration: const InputDecoration(
              icon: Icon(Icons.app_blocking),
              labelText: 'SpatializerRecvRangeID',
              labelStyle: TextStyle(color: Colors.blueGrey, fontSize: 20),
              enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(30)),
                borderSide: BorderSide(color: Colors.blueGrey, width: 2),
              ),
              focusedBorder: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.blueGrey, width: 2),
              ),
            ),
          ),

          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              TextButton.icon(
                label: Text("SetRecvMixStreamCount"),
                onPressed: () async {
                  var recvMixStreamCount = int.parse(
                    _editRecvMixStreamCount.text,
                  );
                  assert(recvMixStreamCount is int);

                  int res = await ITMGContext.GetInstance()
                      .SetRecvMixStreamCount(recvMixStreamCount);
                  if (res == 0) {
                    _showToast("SetRecvMixStreamCount successfully");
                  } else {
                    _showToast("SetRecvMixStreamCount failed");
                  }
                },
                icon: Icon(Icons.family_restroom),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              DropdownButton<String>(
                items: [
                  DropdownMenuItem(
                    child: Text(
                      'Log Default',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: "Doument",
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'Log TestOne',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: "LogTestOne",
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'Log TestTwo',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: "LogTestTwo",
                  ),
                ],
                value: _curLogPath,
                icon: Icon(Icons.description),
                onChanged: (value) async {
                  //if (value == "/Doument") return;
                  final pathObj = await getApplicationDocumentsDirectory();
                  String curPath = pathObj.path;
                  if (value != "Doument") {
                    if (Platform.isWindows) {
                      curPath = curPath + "\\" + value!;
                    } else {
                      curPath = curPath + "/" + value!;
                    }
                  }
                  ITMGContext.GetInstance().SetLogPath(curPath);
                  setState(() {
                    _curLogPath = value!;
                  });
                },
              ),
              Text(" "),
              DropdownButton<int>(
                items: [
                  DropdownMenuItem(
                    child: Text(
                      'None',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: -1,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'Error',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: 1,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'Info',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: 2,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'Debug',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: 3,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'Verbose',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: 4,
                  ),
                ],
                value: _curLogLevel,
                icon: Icon(Icons.edit),
                onChanged: (value) {
                  ITMGContext.GetInstance().SetLogLevel(value!, value);
                  setState(() {
                    _curLogLevel = value;
                  });
                },
              ),
              TextButton.icon(
                onPressed: () async {
                  ITMG_MIC_PERMISSION res =
                      await ITMGContext.GetInstance().CheckMicPermission();
                  switch (res.value) {
                    case 0:
                      {
                        _curMicPermission = "GRANTED";
                      }
                      break;
                    case 1:
                      {
                        _curMicPermission = "Denied";
                      }
                      break;
                    case 2:
                      {
                        _curMicPermission = "NotDetermined";
                      }
                      break;
                    default:
                  }
                  setState(() {
                    _curMicPermission;
                  });
                },
                label: Text("$_curMicPermission"),
                icon: Icon(Icons.perm_scan_wifi_sharp),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              DropdownButton<ITMG_RANGE_AUDIO_MODE>(
                items: [
                  DropdownMenuItem(
                    child: Text(
                      'ALL_REC_ALL',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_ALL_REC_ALL,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'ALL_REC_BOTH',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_ALL_REC_BOTH,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'TEAM_REC_TEAM',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_TEAM_REC_TEAM,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'TEAM_REC_PROX',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_TEAM_REC_PROX,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'TEAM_REC_BOTH',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_TEAM_REC_BOTH,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'PROX_REC_TEAM',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_PROX_REC_TEAM,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'PROX_REC_PROX',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_PROX_REC_PROX,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'PROX_REC_BOTH',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_PROX_REC_BOTH,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'BOTH_REC_TEAM',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_BOTH_REC_TEAM,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'BOTH_REC_PROX',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_BOTH_REC_PROX,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'BOTH_REC_BOTH',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value:
                        ITMG_RANGE_AUDIO_MODE
                            .ITMG_RANGE_AUDIO_MODE_SND_BOTH_REC_BOTH,
                  ),
                ],
                value: _curRangeMode,
                icon: Icon(Icons.date_range),
                onChanged: (ITMG_RANGE_AUDIO_MODE? value) async {
                  if (value != null) {
                    int res = await ITMGContext.GetInstance().SetRangeAudioMode(
                      value,
                    );
                    if (res == 0) {
                      _showToast("Voice mode set successfully");
                    } else {
                      _showToast("Voice mode setting failed");
                    }
                    setState(() {
                      _curRangeMode = value;
                    });
                  }
                },
              ),
              TextButton.icon(
                label: Text("SetTeamID"),
                onPressed: () async {
                  var curTeamId = int.parse(_editTeamID.text);
                  assert(curTeamId is int);

                  int res = await ITMGContext.GetInstance().SetRangeAudioTeamID(
                    curTeamId,
                  );
                  if (res == 0) {
                    _showToast("teamID set successfully");
                  } else {
                    _showToast("teamID set failed");
                  }
                },
                icon: Icon(Icons.family_restroom),
              ),
            ],
          ),
          TextButton.icon(
            label: Text("UpdateSpaRecvRange"),
            onPressed: () async {
              var recvRange = double.parse(
                _editUpdateSpatializerRecvRangeID.text,
              );
              assert(recvRange is double);

              int res = await ITMGContext.GetInstance()
                  .GetRoom()
                  .UpdateSpatializerRecvRange(recvRange);
              if (res == 0) {
                _showToast("teamID set successfully");
              } else {
                _showToast("teamID set failed");
              }
            },
            icon: Icon(Icons.family_restroom),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                "EnableSpatializer",
                style: Theme.of(context).textTheme.labelLarge,
              ),
              Switch(
                value: _switchEnableSpatializer,
                onChanged: OnEnableSpatializer,
              ),

              TextButton.icon(
                onPressed: () async {
                  bool res =
                      await ITMGContext.GetInstance()
                          .GetAudioCtrl()
                          .IsEnableSpatializer();
                  setState(() {
                    _isEnableSpatializer = res;
                  });
                },
                icon: Icon(Icons.twenty_three_mp_rounded),
                label: Text("isEnableSpa:$_isEnableSpatializer"),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              DropdownButton<int>(
                items: [
                  DropdownMenuItem(
                    child: Text(
                      'Small range',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: 1,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'Medium range',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: 2,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'Larger range',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: 3,
                  ),
                  DropdownMenuItem(
                    child: Text(
                      'Huge range',
                      style: Theme.of(context).textTheme.labelLarge,
                    ),
                    value: 5,
                  ),
                ],
                value: _curRangeSize.toInt(),
                icon: Icon(Icons.donut_large),
                onChanged: (value) async {
                  int res = await ITMGContext.GetInstance()
                      .GetRoom()
                      .UpdateAudioRecvRange(value!.toDouble());
                  if (res == 0) {
                    _showToast("Voice mode set successfully");

                    Float32List position = Float32List.fromList([0, 0, 0]);
                    Float32List axisForward = Float32List.fromList([
                      1.0,
                      0.0,
                      0.0,
                    ]);
                    Float32List axisRightward = Float32List.fromList([
                      0.0,
                      1.0,
                      0.0,
                    ]);
                    Float32List axisUpward = Float32List.fromList([
                      0.0,
                      0.0,
                      1.0,
                    ]);
                    res = await ITMGContext.GetInstance()
                        .GetRoom()
                        .UpdateSelfPosition(
                          position,
                          axisForward,
                          axisRightward,
                          axisUpward,
                        );
                    print(res);
                  } else {
                    _showToast("Voice mode setting failed");
                  }
                  setState(() {
                    _curRangeSize = value!.toDouble();
                  });
                },
              ),
              TextButton.icon(
                label: Text("UpdatePosition"),
                onPressed: () async {
                  showUpdateSelfParamPicker();
                },
                icon: Icon(Icons.update_sharp),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              TextButton.icon(
                onPressed: () async {
                  int res =
                      await ITMGContext.GetInstance()
                          .GetAudioCtrl()
                          .GetMicLevel();
                  setState(() {
                    _curMicLevel = res;
                  });
                },
                icon: Icon(Icons.stream),
                label: Text("GetMicLevel:$_curMicLevel"),
              ),
              TextButton.icon(
                onPressed: () async {
                  int res =
                      await ITMGContext.GetInstance()
                          .GetAudioCtrl()
                          .GetSpeakerLevel();
                  setState(() {
                    _curSpeakerLevel = res;
                  });
                },
                icon: Icon(Icons.twenty_three_mp_rounded),
                label: Text("GetSpeakerLevel:$_curSpeakerLevel"),
              ),
            ],
          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      String res = await ITMGContext.GetInstance()
                          .GetAdvanceParams(_advanceParams);
                      setState(() {
                        _curAdvanceValue = res;
                      });
                    },
                    icon: Icon(Icons.airplanemode_active),
                    label: Text("$_curAdvanceValue"),
                  ),

                  TextButton.icon(
                    onPressed: () async {
                      bool enable = false;
                      enable =
                          ITMGContext.GetInstance()
                              .GetAudioCtrl()
                              .IsAudioRecvEnabled();
                      setState(() {
                        _enable_recv = enable;
                      });
                    },
                    icon: Icon(Icons.twenty_three_mp_rounded),
                    label: Text("isRecvEnabled:$_enable_recv"),
                  ),
                ],
              ),
            ],
          ),

          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      bool enable = false;
                      enable =
                          ITMGContext.GetInstance()
                              .GetAudioCtrl()
                              .IsAudioCaptureDeviceEnabled();
                      setState(() {
                        _enable_capture = enable;
                      });
                    },
                    icon: Icon(Icons.twenty_three_mp_rounded),
                    label: Text("isCapEnabled:$_enable_capture"),
                  ),

                  TextButton.icon(
                    onPressed: () async {
                      bool enable = false;
                      enable =
                          ITMGContext.GetInstance()
                              .GetAudioCtrl()
                              .IsAudioSendEnabled();
                      setState(() {
                        _enableAudioSend = enable;
                      });
                    },
                    icon: Icon(Icons.twenty_three_mp_rounded),
                    label: Text("IsAudioSend:$_enableAudioSend"),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Expanded(
                    child: TextField(
                      controller: _editcustomDataID,
                      decoration: const InputDecoration(
                        icon: Icon(Icons.pest_control_rodent_outlined),
                        labelText: 'Custom Data',
                        hintMaxLines: 100,
                        labelStyle: TextStyle(
                          color: Colors.blueGrey,
                          fontSize: 20,
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(30)),
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                      ),
                    ),
                  ),
                  const SizedBox(width: 10),
                  Expanded(
                    child: TextField(
                      controller: _editcustomRepeatCountID,
                      decoration: const InputDecoration(
                        icon: Icon(Icons.pest_control_rodent_outlined),
                        labelText: 'Repeat Count',
                        hintMaxLines: 100,
                        labelStyle: TextStyle(
                          color: Colors.blueGrey,
                          fontSize: 20,
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(30)),
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.blueGrey,
                            width: 2,
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  TextButton.icon(
                    onPressed: () async {
                      int res = await ITMGContext.GetInstance()
                          .GetRoom()
                          .SendSEIMsg(
                            _editcustomDataID.text,
                            int.parse(_editcustomRepeatCountID.text),
                          );
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      } else {
                        _showToast("SendSEIMsg successfully");
                      }
                    },
                    icon: Icon(Icons.switch_video),
                    label: Text("SendSEIMsg"),
                  ),
                  Text(
                    'SendCustomData',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(
                    value: _switchSendCustomData,
                    onChanged: SendCustomData,
                  ),
                ],
              ),
              TextField(
                controller: _editRoomManagerID,
                decoration: const InputDecoration(
                  icon: Icon(Icons.pest_control_rodent_outlined),
                  labelText: 'Ctrl receiverID',
                  hintMaxLines: 100,
                  labelStyle: TextStyle(color: Colors.blueGrey, fontSize: 20),
                  enabledBorder: OutlineInputBorder(
                    /*边角*/
                    borderRadius: BorderRadius.all(
                      Radius.circular(30), //边角为30
                    ),
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边线颜色为黄色
                      width: 2, //边线宽度为2
                    ),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边框颜色为绿色
                      width: 2, //宽度为5
                    ),
                  ),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text("BlackList"),
                  Switch(
                    value: _roomUserBlock,
                    onChanged: (value) async {
                      int res = 0;
                      if (value) {
                        res = await ITMGContext.GetInstance()
                            .GetAudioCtrl()
                            .AddAudioBlackList(_editRoomManagerID.text);
                        if (res != 0) {
                          showCupertinoAlertDialog(
                            "Operation Failed",
                            "Unable to operate AddAudioBlackList, please check the error code $res",
                          );
                          return;
                        }
                      } else {
                        res = await ITMGContext.GetInstance()
                            .GetAudioCtrl()
                            .RemoveAudioBlackList(_editRoomManagerID.text);
                        if (res != 0) {
                          showCupertinoAlertDialog(
                            "Operation Failed",
                            "Unable to operate RemoveAudioBlackList, please check the error code $res",
                          );
                          return;
                        }
                      }
                      setState(() {
                        _roomUserBlock = value;
                      });
                    },
                  ),

                  TextButton.icon(
                    onPressed: () async {
                      bool enable = false;
                      enable = ITMGContext.GetInstance()
                          .GetAudioCtrl()
                          .IsUserIDInAudioBlackList(_editRoomManagerID.text);
                      setState(() {
                        _inBlacklist = enable;
                      });
                    },
                    icon: Icon(Icons.twenty_three_mp_rounded),
                    label: Text("IsUserInBlack:$_inBlacklist"),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      int res = await ITMGContext.GetInstance()
                          .GetAudioCtrl()
                          .GetSpeakerVolumeByUserID(_editRoomManagerID.text);
                      setState(() {
                        _otherGetSpkVol = res;
                      });
                    },
                    label: Text("SpkVol:$_otherGetSpkVol"),
                    icon: Icon(Icons.mic_external_on_sharp),
                  ),
                  Icon(Icons.speaker),
                  Slider(
                    value: _otherSpkVolume,
                    activeColor: Colors.blueGrey,
                    inactiveColor: Colors.grey,
                    label: 'otherSpk:$_otherSpkVolume',
                    min: 0,
                    max: 200,
                    divisions: 50,
                    onChangeEnd: (value) async {
                      int volume = value.toInt();
                      int res = await ITMGContext.GetInstance()
                          .GetAudioCtrl()
                          .SetSpeakerVolumeByUserID(
                            _editRoomManagerID.text,
                            volume,
                          );
                      if (res != 0) {
                        _showToast(
                          "Failed to set other people's speaker volume",
                        );
                      }
                    },
                    onChanged: (value) {
                      setState(() {
                        int curValue = value.toInt();
                        _otherSpkVolume = curValue.toDouble();
                      });
                    },
                  ),
                ],
              ),
              Row(
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      int res =
                          await ITMGContext.GetInstance()
                              .GetAudioCtrl()
                              .GetSendStreamLevel();
                      setState(() {
                        _curSendStreamLevel = res;
                      });
                    },
                    icon: Icon(Icons.window),
                    label: Text("GetSendStreamLevel:$_curSendStreamLevel"),
                  ),
                ],
                mainAxisAlignment: MainAxisAlignment.center,
              ),
              Row(
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      int res = await ITMGContext.GetInstance()
                          .GetAudioCtrl()
                          .GetRecvStreamLevel(_editRoomManagerID.text);
                      setState(() {
                        _curRecvStreamLevel = res;
                      });
                    },
                    icon: Icon(Icons.laptop_windows),
                    label: Text("GetRecvStreamLevel:$_curRecvStreamLevel"),
                  ),
                ],
                mainAxisAlignment: MainAxisAlignment.center,
              ),
            ],
          ),

          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              TextField(
                controller: _editOtherRoomID,
                decoration: const InputDecoration(
                  icon: Icon(Icons.meeting_room_sharp),
                  labelText: 'Other RoomID',
                  hintMaxLines: 100,
                  labelStyle: TextStyle(color: Colors.blueGrey, fontSize: 20),
                  enabledBorder: OutlineInputBorder(
                    /*边角*/
                    borderRadius: BorderRadius.all(
                      Radius.circular(30), //边角为30
                    ),
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边线颜色为黄色
                      width: 2, //边线宽度为2
                    ),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边框颜色为绿色
                      width: 2, //宽度为5
                    ),
                  ),
                ),
              ),
              Text(""),
              TextField(
                controller: _editOtherOpenID,
                decoration: const InputDecoration(
                  icon: Icon(Icons.personal_injury),
                  labelText: 'Other OpenID',
                  hintMaxLines: 100,
                  labelStyle: TextStyle(color: Colors.blueGrey, fontSize: 20),
                  enabledBorder: OutlineInputBorder(
                    /*边角*/
                    borderRadius: BorderRadius.all(
                      Radius.circular(30), //边角为30
                    ),
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边线颜色为黄色
                      width: 2, //边线宽度为2
                    ),
                  ),
                  focusedBorder: OutlineInputBorder(
                    borderSide: BorderSide(
                      color: Colors.blueGrey, //边框颜色为绿色
                      width: 2, //宽度为5
                    ),
                  ),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      authBuffer = await ITMGContext.GetInstance()
                          .GenAuthBuffer(
                            int.parse(_editAppID.text),
                            _editOtherRoomID.text,
                            _editOpenID.text,
                            _editKey.text,
                          );
                      int res = await ITMGContext.GetInstance()
                          .GetRoom()
                          .SwitchRoom(_editOtherRoomID.text, authBuffer!);
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      } else {
                        _showToast("SwitchRoom successfully");
                      }
                    },
                    icon: Icon(Icons.switch_video),
                    label: Text("SwitchRoom"),
                  ),
                  Text('share', style: Theme.of(context).textTheme.labelLarge),
                  Switch(
                    value: _switchRoomSharing,
                    onChanged: (value) async {
                      int res = 0;
                      if (value) {
                        res = await ITMGContext.GetInstance()
                            .GetRoom()
                            .StartRoomSharing(
                              _editOtherRoomID.text,
                              _editOtherOpenID.text,
                            );
                      } else {
                        res =
                            await ITMGContext.GetInstance()
                                .GetRoom()
                                .StopRoomSharing();
                      }

                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      }
                      setState(() {
                        _switchRoomSharing = value;
                      });
                    },
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Expanded(
                    child: TextField(
                      controller: _editMusicNameID,
                      decoration: const InputDecoration(
                        icon: Icon(Icons.meeting_room_sharp),
                        labelText: 'music',
                        hintMaxLines: 100,
                        labelStyle: TextStyle(
                          color: Colors.blueGrey,
                          fontSize: 20,
                        ),
                        enabledBorder: OutlineInputBorder(
                          /*边角*/
                          borderRadius: BorderRadius.all(
                            Radius.circular(30), //边角为30
                          ),
                          borderSide: BorderSide(
                            color: Colors.blueGrey, //边线颜色为黄色
                            width: 2, //边线宽度为2
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.blueGrey, //边框颜色为绿色
                            width: 2, //宽度为5
                          ),
                        ),
                      ),
                    ),
                  ),
                  Expanded(
                    child: TextField(
                      controller: _editMusicID,
                      decoration: const InputDecoration(
                        icon: Icon(Icons.meeting_room_sharp),
                        labelText: 'sound Id',
                        hintMaxLines: 100,
                        labelStyle: TextStyle(
                          color: Colors.blueGrey,
                          fontSize: 20,
                        ),
                        enabledBorder: OutlineInputBorder(
                          /*边角*/
                          borderRadius: BorderRadius.all(
                            Radius.circular(30), //边角为30
                          ),
                          borderSide: BorderSide(
                            color: Colors.blueGrey, //边线颜色为黄色
                            width: 2, //边线宽度为2
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.blueGrey, //边框颜色为绿色
                            width: 2, //宽度为5
                          ),
                        ),
                      ),
                    ),
                  ),
                  Expanded(
                    child: TextField(
                      controller: _editMusicPlayCountID,
                      decoration: const InputDecoration(
                        icon: Icon(Icons.meeting_room_sharp),
                        labelText: 'loop count',
                        hintMaxLines: 100,
                        labelStyle: TextStyle(
                          color: Colors.blueGrey,
                          fontSize: 20,
                        ),
                        enabledBorder: OutlineInputBorder(
                          /*边角*/
                          borderRadius: BorderRadius.all(
                            Radius.circular(30), //边角为30
                          ),
                          borderSide: BorderSide(
                            color: Colors.blueGrey, //边线颜色为黄色
                            width: 2, //边线宽度为2
                          ),
                        ),
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                            color: Colors.blueGrey, //边框颜色为绿色
                            width: 2, //宽度为5
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'playMusic',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(
                    value: _switchPlayMusic,
                    onChanged: (value) async {
                      int res = 0;
                      Duration totalLen = Duration.zero;
                      if (value) {
                        String  accompyFileDir = "";
                        if (_editMusicNameID.text.startsWith("https://") || _editMusicNameID.text.startsWith("http://")) {
                          accompyFileDir = _editMusicNameID.text;
                        }
                        else if(_editMusicNameID.text == "record.aac") {
                          accompyFileDir = _recordFilePath;
                        } else {
                          accompyFileDir = _accompyFileDir + _editMusicNameID.text;
                        }
                        res = ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .StartPlayMusic(
                              int.parse(_editMusicID.text),
                              accompyFileDir,
                              int.parse(_editMusicPlayCountID.text),
                            );

                        if (res != 0) {
                          showCupertinoAlertDialog(
                            "Invalid operation",
                            "Please check the error code $res",
                          );
                          return;
                        }
                        _musicSoundID = int.parse(_editMusicID.text);
                      } else {
                        res = ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .StopPlayMusic(int.parse(_editMusicID.text));
                        _progressTime!.cancel();
                        _accompySchedule = Duration.zero;
                      }
                      setState(() {
                        _switchPlayMusic = value;
                        if (!value) {
                          _pausePlayMusic = value;
                        }
                      });
                      progressTimer();
                    },
                  ),
                  Text(
                    'pauseMusic',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),

                  Switch(
                    value: _pausePlayMusic,
                    onChanged: (value) async {
                      int res = 0;
                      if (value) {
                        res = await ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .PausePlayMusic(int.parse(_editMusicID.text));
                      } else {
                        res = await ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .ResumePlayMusic(int.parse(_editMusicID.text));
                      }

                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      }
                      setState(() {
                        _pausePlayMusic = value;
                      });
                    },
                  ),
                ],
              ),

              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'musicPublish',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(
                    value: _switchEnableMusicPublish,
                    onChanged: (value) async {
                      int res = ITMGContext.GetInstance()
                          .GetAudioEffectCtrl()
                          .EnableMusicPublish(
                            int.parse(_editMusicID.text),
                            value,
                          );
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      }
                      setState(() {
                        _switchEnableMusicPublish = value;
                      });
                    },
                  ),
                  Text(
                    'musicPlayout',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),

                  Switch(
                    value: _switchEnableMusicPlayout,
                    onChanged: (value) async {
                      int res = ITMGContext.GetInstance()
                          .GetAudioEffectCtrl()
                          .EnableMusicPlayout(
                            int.parse(_editMusicID.text),
                            value,
                          );
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      }
                      setState(() {
                        _switchEnableMusicPlayout = value;
                      });
                    },
                  ),
                ],
              ),

              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      bool res = await ITMGContext.GetInstance()
                          .GetAudioEffectCtrl()
                          .IsMusicPlayEnd(int.parse(_editMusicID.text));
                      setState(() {
                        if (res) {
                          _strMusicPlayEnd = "Yes";
                        } else {
                          _strMusicPlayEnd = "Not";
                        }
                      });
                    },
                    icon: Icon(Icons.room_outlined),
                    label: Text("$_strMusicPlayEnd"),
                  ),
                ],
              ),
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Slider(
                    value:
                        _accompyLens.inMilliseconds == 0
                            ? 0
                            : _accompySchedule.inMilliseconds.toDouble(),
                    min: 0,
                    max: _accompyLens.inMilliseconds.toDouble(),
                    divisions: 100,
                    label:
                        "${(_accompySchedule.inMilliseconds / _accompyLens.inMilliseconds * 100).toStringAsFixed(0)}%",
                    activeColor: Colors.blue,
                    inactiveColor: Colors.grey,
                    onChanged: (value) {
                      setState(() {
                        _accompySchedule = Duration(
                          milliseconds: value.toInt(),
                        );
                      });
                      // Update playback progress here (e.g., call a method to seek)
                      ITMGContext.GetInstance()
                          .GetAudioEffectCtrl()
                          .SeekMusicToPosInTime(
                            int.parse(_editMusicID.text),
                            _accompySchedule.inMilliseconds,
                          );
                    },
                    onChangeEnd: (value) {
                      print('Drag Ended at ${value.toInt()}ms');
                    },
                  ),
                ],
              ),

              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'SetAllMusicVol:',
                    style: TextStyle(color: Colors.blueGrey, fontSize: 12),
                  ),
                  SizedBox(width: 10),
                  Slider(
                    value: _allMusicVolume,
                    label: 'allMusicVolume:$_allMusicVolume',
                    activeColor: Colors.blueGrey,
                    inactiveColor: Colors.grey,
                    min: 0,
                    max: 200,
                    divisions: 50,
                    onChanged: (value) {
                      setState(() {
                        int curValue = value.toInt();
                        _allMusicVolume = curValue.toDouble();
                      });
                    },
                    onChangeEnd: (value) {
                      setState(() {
                        int curValue = value.toInt();
                        // Set Accompy Value
                        ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .SetAllMusicVolume(curValue);
                      });
                    },
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'SetMusicPitch:',
                    style: TextStyle(color: Colors.blueGrey, fontSize: 12),
                  ),
                  SizedBox(width: 10),
                  Slider(
                    value: _musicPitch,
                    label: 'musicPitch:$_musicPitch',
                    activeColor: Colors.blueGrey,
                    inactiveColor: Colors.grey,
                    min: -1,
                    max: 1,
                    divisions: 50,
                    onChanged: (value) {
                      setState(() {
                        _musicPitch = value;
                      });
                    },
                    onChangeEnd: (value) {
                      setState(() {
                        ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .SetMusicPitch(int.parse(_editMusicID.text), value);
                      });
                    },
                  ),
                ],
              ),

              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      int res = await ITMGContext.GetInstance()
                          .GetAudioEffectCtrl()
                          .GetMusicPublishVolume(int.parse(_editMusicID.text));
                      setState(() {
                        _nMusicPublishVolume = res;
                      });
                    },
                    icon: Icon(Icons.mic_none),
                    label: Text("publishVol: $_nMusicPublishVolume"),
                  ),
                  Slider(
                    value: _musicPublishVolume,
                    label: 'publishVolume:$_musicPublishVolume',
                    activeColor: Colors.blueGrey,
                    inactiveColor: Colors.grey,
                    min: 0,
                    max: 200,
                    divisions: 50,
                    onChanged: (value) {
                      // if (_accompyState == false) {
                      //   return;
                      // }
                      setState(() {
                        int curValue = value.toInt();
                        _musicPublishVolume = curValue.toDouble();
                      });
                    },
                    onChangeEnd: (value) {
                      setState(() {
                        int curValue = value.toInt();
                        // Set Accompy Value
                        ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .SetMusicPublishVolume(
                              int.parse(_editMusicID.text),
                              curValue,
                            );
                      });
                    },
                  ),
                ],
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  TextButton.icon(
                    onPressed: () async {
                      int res = await ITMGContext.GetInstance()
                          .GetAudioEffectCtrl()
                          .GetMusicPlayoutVolume(int.parse(_editMusicID.text));
                      setState(() {
                        _nMusicPlayoutVolume = res;
                      });
                    },
                    icon: Icon(Icons.mic_external_on_rounded),
                    label: Text("PlayoutVol: $_nMusicPlayoutVolume"),
                  ),
                  Slider(
                    value: _musicPlayoutVolume,
                    label: 'playoutVolume:$_nMusicPlayoutVolume',
                    activeColor: Colors.blueGrey,
                    inactiveColor: Colors.grey,
                    min: 0,
                    max: 200,
                    divisions: 50,
                    onChanged: (value) {
                      setState(() {
                        int curValue = value.toInt();
                        _musicPlayoutVolume = curValue.toDouble();
                      });
                    },
                    onChangeEnd: (value) {
                      setState(() {
                        int curValue = value.toInt();
                        // Set Accompy Value
                        ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .SetMusicPlayoutVolume(
                              int.parse(_editMusicID.text),
                              curValue,
                            );
                      });
                    },
                  ),
                ],
              ),

              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  DropdownButton<ITMG_VOICE_TYPE>(
                    items: [
                      DropdownMenuItem(
                        child: Text(
                          "关闭音效",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_ORIGINAL_SOUND,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "幼稚园",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_KINDER_GARTEN,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "萝莉",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_LOLITA,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "大叔",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_UNCLE,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "重金属",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_HEAVY_MENTAL,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "感冒",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_INFLUENZA,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "歪果仁",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_DIALECT,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "困兽",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_CAGED_ANIMAL,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "死肥宅",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_DEAD_FATBOY,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "强电流",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_STRONG_CURRENT,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "重机器",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_HEAVY_MACHINE,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "空灵",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_VOICE_TYPE.ITMG_VOICE_TYPE_INTANGIBLE,
                      ),
                    ],
                    icon: Icon(Icons.record_voice_over_outlined),
                    value: _nVoiceType,
                    onChanged: (value) async {
                      int res = 0;
                      if (value != null) {
                        res = ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .SetVoiceType(value);
                      }
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      }
                      setState(() {
                        if (value == null) return;
                        _nVoiceType = value;
                      });
                    },
                  ),

                  DropdownButton<ITMG_KARAOKE_TYPE>(
                    items: [
                      DropdownMenuItem(
                        child: Text(
                          "关闭混响",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_0,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "KTV",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_1,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "小房间",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_2,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "大会堂",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_3,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "低沉",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_4,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "洪亮",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_5,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "金属声",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_6,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "磁性",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_7,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "空灵",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_8,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "录音棚",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_9,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "悠扬",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_10,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "录音棚2",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value: ITMG_KARAOKE_TYPE.ITMG_KARAOKE_TYPE_11,
                      ),
                    ],
                    icon: Icon(Icons.record_voice_over_outlined),
                    value: _nKaraokeType,
                    onChanged: (value) async {
                      int res = 0;
                      if (value != null) {
                        res = ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .SetKaraokeType(value);
                      }
                      if (res != 0) {
                        showCupertinoAlertDialog(
                          "Invalid operation",
                          "Please check the error code $res",
                        );
                        return;
                      }
                      setState(() {
                        if (value == null) return;
                        _nKaraokeType = value;
                      });
                    },
                  ),
                ],
              ),

              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  DropdownButton<ITMG_AUDIO_RECORDING_CONTENT>(
                    items: [
                      DropdownMenuItem(
                        child: Text(
                          "RECORDING_ALL",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value:
                            ITMG_AUDIO_RECORDING_CONTENT
                                .ITMG_AUDIO_RECORDING_CONTENT_ALL,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "RECORDING_LOCAL",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value:
                            ITMG_AUDIO_RECORDING_CONTENT
                                .ITMG_AUDIO_RECORDING_CONTENT_LOCAL,
                      ),
                      DropdownMenuItem(
                        child: Text(
                          "RECORDING_REMOTE",
                          style: Theme.of(context).textTheme.labelLarge,
                        ),
                        value:
                            ITMG_AUDIO_RECORDING_CONTENT
                                .ITMG_AUDIO_RECORDING_CONTENT_REMOTE,
                      ),
                    ],
                    icon: Icon(Icons.record_voice_over_outlined),
                    value: _nRecordingType,
                    onChanged: (value) async {
                      setState(() {
                        if (value == null) return;
                        _nRecordingType = value;
                      });
                    },
                  ),

                  Text(
                    'startRecord',
                    style: Theme.of(context).textTheme.labelLarge,
                  ),
                  Switch(
                    value: _switchRecordStart,
                    onChanged: (value) async {
                      if (value) {
                        int res = await ITMGContext.GetInstance()
                            .GetAudioEffectCtrl()
                            .StartRecord(_recordFilePath, _nRecordingType);
                        if (res != 0) {
                          showCupertinoAlertDialog(
                            "Invalid operation",
                            "Please check the error code $res",
                          );
                          return;
                        }
                        String recordMsg =
                            'Start recordFilePath: ' + _recordFilePath;
                        _showToast(recordMsg);
                      } else {
                        int res =
                            await ITMGContext.GetInstance()
                                .GetAudioEffectCtrl()
                                .StopRecord();
                        if (res != 0) {
                          showCupertinoAlertDialog(
                            "Invalid operation",
                            "Please check the error code $res",
                          );
                          return;
                        }

                        _showToast(
                          "Finish recording, please view the file locally",
                        );
                      }
                      setState(() {
                        _switchRecordStart = value;
                      });
                    },
                  ),
                ],
              ),
            ],
          ),
          Text('$_callbackMessage'),
          Text('Gme Version:$_sdkVersions'),
        ],
      ),
    );
  }
}
