fix: 暂缓,改为sdk接入开发
This commit is contained in:
parent
9bab2cde56
commit
10ccc40b6a
@ -74,6 +74,6 @@ class AppInitialization {
|
||||
..textColor = Colors.yellow
|
||||
..maskColor = Colors.blue.withOpacity(0.5)
|
||||
..userInteractions = false
|
||||
..dismissOnTap = false;
|
||||
..dismissOnTap = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ class F {
|
||||
// Release环境的API地址
|
||||
switch (appFlavor) {
|
||||
case Flavor.sky:
|
||||
return 'https://api.skychip.top/api'; // 生产环境API
|
||||
return 'https://192.168.1.121:8112/api'; // 生产环境API
|
||||
case Flavor.xhj:
|
||||
return 'https://api.xhjcn.ltd/api'; // 生产环境API
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ import 'dart:math';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:starcloud/entity/star_cloud_lock_list.dart';
|
||||
import 'package:starcloud/entity/star_cloud_scan_result.dart';
|
||||
import 'package:starcloud/sdk/entity/cloud_user_info.dart';
|
||||
import 'package:starcloud/sdk/sdk_device_operate_extension.dart';
|
||||
import 'package:starcloud/sdk/starcloud.dart';
|
||||
import 'package:starwork_flutter/base/app_logger.dart';
|
||||
@ -45,7 +46,7 @@ class SearchDeviceController extends BaseController {
|
||||
void onReady() {
|
||||
super.onReady();
|
||||
// 开始搜索
|
||||
_startBluetoothSearch();
|
||||
_initializePermissions();
|
||||
}
|
||||
|
||||
@override
|
||||
@ -77,6 +78,9 @@ class SearchDeviceController extends BaseController {
|
||||
|
||||
// 开始搜索
|
||||
await _startBluetoothSearch();
|
||||
|
||||
// 开始搜索
|
||||
await _startBluetoothSearch();
|
||||
} catch (e, stackTrace) {
|
||||
AppLogger.error('权限初始化失败', error: e, stackTrace: stackTrace);
|
||||
showToast('权限初始化失败,请重试');
|
||||
@ -93,9 +97,13 @@ class SearchDeviceController extends BaseController {
|
||||
isSearching.value = true;
|
||||
|
||||
// 启动搜索设备
|
||||
StarCloudSDK.instance.scanDeviceList(onScan: (List<StarCloudScanResult> deviceListResult) {
|
||||
deviceList.value = deviceListResult;
|
||||
});
|
||||
await StarCloudSDK.instance.scanDeviceList(
|
||||
onScan: (List<StarCloudScanResult> deviceListResult) {
|
||||
AppLogger.highlight('deviceListResult:${deviceListResult}');
|
||||
deviceList.value = deviceListResult;
|
||||
},
|
||||
timeout: 10,
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
AppLogger.error('启动蓝牙搜索失败', error: e, stackTrace: stackTrace);
|
||||
isSearching.value = false;
|
||||
@ -103,18 +111,12 @@ class SearchDeviceController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新设备数据
|
||||
/// 刷新设备数据
|
||||
Future<void> refreshDevices() async {
|
||||
AppLogger.highlight('🔄 开始刷新设备列表');
|
||||
|
||||
if (!permissionsGranted.value) {
|
||||
AppLogger.warn('⚠️ 权限未就绪,无法刷新');
|
||||
showToast('请先授权必要的权限');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
StarCloudSDK.instance.stopScan(onError: (err) {});
|
||||
await StarCloudSDK.instance.stopScan(onError: (err) {});
|
||||
isSearching.value = false;
|
||||
|
||||
// 清空设备列表
|
||||
@ -123,8 +125,8 @@ class SearchDeviceController extends BaseController {
|
||||
// 模拟网络请求延迟
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
// 重新开始搜索
|
||||
await _startBluetoothSearch();
|
||||
// 重新开始搜索前检查权限
|
||||
await _initializePermissions();
|
||||
|
||||
AppLogger.highlight('✅ 设备列表刷新完成');
|
||||
} catch (e, stackTrace) {
|
||||
@ -139,13 +141,16 @@ class SearchDeviceController extends BaseController {
|
||||
/// 3.注册管理员密码
|
||||
void connectingDevices(StarCloudScanResult device) async {
|
||||
showLoading();
|
||||
|
||||
try {
|
||||
var cacheStarCloudUserName = await SharedPreferencesUtils.getString(CacheKeys.starCloudUserName);
|
||||
var starCloudPassword = await SharedPreferencesUtils.getString(CacheKeys.starCloudPassword);
|
||||
var starCloudUid = await SharedPreferencesUtils.getString(CacheKeys.starCloudUid);
|
||||
if (cacheStarCloudUserName == null || starCloudPassword == null || starCloudUid == null) {
|
||||
StarCloudSDK.instance.createCloudUser(
|
||||
onError: (err) {},
|
||||
var cacheStarCloudPassword = await SharedPreferencesUtils.getString(CacheKeys.starCloudPassword);
|
||||
var cacheStarCloudUid = await SharedPreferencesUtils.getString(CacheKeys.starCloudUid);
|
||||
if (cacheStarCloudUserName == null || cacheStarCloudPassword == null || cacheStarCloudUid == null) {
|
||||
await StarCloudSDK.instance.createCloudUser(
|
||||
onError: (err) {
|
||||
AppLogger.error('err:${err}');
|
||||
},
|
||||
onSuccess: (userInfo) {
|
||||
SharedPreferencesUtils.setString(CacheKeys.starCloudUserName, userInfo.username);
|
||||
SharedPreferencesUtils.setString(CacheKeys.starCloudPassword, userInfo.password);
|
||||
@ -153,8 +158,19 @@ class SearchDeviceController extends BaseController {
|
||||
},
|
||||
);
|
||||
}
|
||||
StarCloudSDK.instance.pairDevice(
|
||||
onError: (err) {},
|
||||
StarCloudSDK.instance.setCloudAccounts(
|
||||
[
|
||||
CloudUserInfo(
|
||||
username: cacheStarCloudUserName!,
|
||||
password: cacheStarCloudPassword!,
|
||||
uid: int.parse(cacheStarCloudUid!),
|
||||
)
|
||||
],
|
||||
);
|
||||
await StarCloudSDK.instance.pairDevice(
|
||||
onError: (err) {
|
||||
AppLogger.error('err:${err}');
|
||||
},
|
||||
onSuccess: (StarCloudLock lockInfo) {
|
||||
AppLogger.highlight('lockInfo:${lockInfo.toString()}');
|
||||
},
|
||||
|
||||
@ -173,8 +173,9 @@ class SearchDeviceView extends GetView<SearchDeviceController> {
|
||||
}
|
||||
|
||||
_buildItem({required StarCloudScanResult device, required int index}) {
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
onTap: () async {
|
||||
controller.connectingDevices(device);
|
||||
},
|
||||
child: Container(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user