|
- import 'dart:convert';
-
- import 'package:demo001/scenes/login/login_view.dart';
- import 'package:demo001/scenes/public.dart';
- import 'package:demo001/tools/http_utils.dart';
- import 'package:flutter_easyloading/flutter_easyloading.dart';
- import 'package:get/get.dart';
- import 'package:logger/logger.dart';
- import 'package:permission_handler/permission_handler.dart';
- import 'home_state.dart';
-
- /// @description:
- /// @author
- /// @date: 2025-01-07 15:51:34
- class HomeLogic extends GetxController {
- final state = HomeState();
-
- //1.已连接到的蓝牙,2.失去连接的蓝牙
- final String _bluetoothConnectStateKey = "bluetoothConnected";
- final String _bluetoothDisConnectStateKey = "bluetoothDisConnect";
- //1.已经连接的蓝牙
- final String _bluetoothAlreadyConnectKey = "bluetoothAlreadyConnected";
-
- @override
- void onInit() {
- super.onInit();
- _getLoginInfo();
- _checkPermission();
- _checkConnectDevice();
- _checkBluetoothStatus();
- }
-
- void _checkPermission() {
- Permission.microphone.request();
- state.methodChannel.invokeMethod("bluetoothPermissionRequest");
- }
-
- void _checkBluetoothStatus() {}
-
- ///获取登录信息
- void _getLoginInfo() async {
- final info = await getSharedLoginInfo();
- if (info != null) {
- state.loginModel = info;
- _getAliToken();
- } else {
- EasyLoading.showError('登录过期');
- Get.offAll(() => LoginScene());
- }
- }
-
- void _getAliToken() {
- ApiClient.post(
- url: '/api/home/auth_alitoken',
- token: state.loginModel!.data!.token!,
- param: {},
- onSuccess: (data) {
- // Logger().i('---------_getAliToken--------token-:${data.runtimeType}');
- // Logger().i('---------_getAliToken--------token-:${data['data']['token']}');
- state.loginModel?.ali_appkey = data['data']['appkey'];
- state.loginModel?.ali_token = data['data']['token'];
- },
- onFailed: (msg) {
- Logger().e('-------_getAliToken-------error-$msg');
- });
- }
-
- ///原生传回的数据监听
- void _phoneCallRecordingListenner() {
- state.eventChannel.receiveBroadcastStream((data) {});
- }
-
- //开始监听蓝牙连接设备状态
- void _checkConnectDevice() {
- state.methodChannel.invokeMethod('checkConnectedBluetooth');
- }
-
- ///通话翻译按钮点击
- void startPhoneCallRecording() {
- state.methodChannel.invokeMethod('startPhoneCallRecording');
- }
-
- ///停止通讯录音
- void stopPhoneCallRecording() {
- state.methodChannel.invokeMethod('stopPhoneCallRecording');
- }
-
- //打开蓝牙扫描界面
- void toBonding() {}
-
- ///**************通话录音翻译*************** */
- }
|