diff --git a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart b/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart index 3e71cb1fd..4e60d798d 100644 --- a/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart +++ b/lib/modules/ota_upgrade/controllers/ota_upgrade_controller.dart @@ -177,9 +177,9 @@ class OtaUpgradeController extends GetxController { // 版本更新 Future checkUpdate() async { try { - if (latestVersion.value != "") + if (latestVersion.value != "") { _showUpdateDialog(latestVersion.value); - else { + } else { Get.snackbar('错误', '获取最新版本信息失败'); } } catch (e) { @@ -187,26 +187,28 @@ class OtaUpgradeController extends GetxController { } } - // 显示更新对话框 - void _showUpdateDialog(String latest) { + void _showUpdateDialog(String latest) async { + print('显示更新对话框'); Get.dialog( AlertDialog( title: Text('发现新版本 $latest'), content: Text('是否立即更新?'), actions: [ TextButton( - onPressed: () { - if (Get.isDialogOpen!) { - Get.back(); // 确保只关闭对话框 - } + onPressed: () async { + print('取消按钮被点击'); + + Get.back(); + Future.delayed(Duration(milliseconds: 300)); }, child: Text('取消'), ), TextButton( - onPressed: () { - if (Get.isDialogOpen!) { - Get.back(); // 确保只关闭对话框 - } + onPressed: () async { + print('更新按钮被点击'); + + Get.back(); + Future.delayed(Duration(milliseconds: 300)); startDownload(); }, child: Text('更新'), @@ -266,7 +268,7 @@ class OtaUpgradeController extends GetxController { if (existingSameFile) { Get.snackbar('文件已存在', '跳过下载,直接更新'); - _installApp(savePath); + startUpgrading(savePath); return; } @@ -309,7 +311,7 @@ class OtaUpgradeController extends GetxController { Get.snackbar('错误', '文件未找到,请检查写入权限'); } isDownloading.value = false; - _installApp(savePath); + startUpgrading(savePath); return; } on DioException catch (e) { Get.snackbar('下载失败', '错误: ${e.message}'); @@ -321,8 +323,8 @@ class OtaUpgradeController extends GetxController { } // 开始升级 - void _installApp(String path) async { - jlota.searchDevices(path); + void startUpgrading(String path) async { + jlota.startUpgrading(path); return; // isUpgrade.value = false; } diff --git a/local_plugins/ota/android/src/main/kotlin/com/example/ota/OtaPlugin.kt b/local_plugins/ota/android/src/main/kotlin/com/example/ota/OtaPlugin.kt index 7dcc198b0..f082e3dad 100644 --- a/local_plugins/ota/android/src/main/kotlin/com/example/ota/OtaPlugin.kt +++ b/local_plugins/ota/android/src/main/kotlin/com/example/ota/OtaPlugin.kt @@ -289,8 +289,8 @@ class OtaPlugin : BleService.Callback, FlutterPlugin, MethodCallHandler { } override fun onMethodCall(call: MethodCall, result: Result) { - if (call.method == "searchDevices") { - Log.d("TAG", "searchDevices") + if (call.method == "startUpgrading") { + Log.d("TAG", "startUpgrading") // 接收传入的参数 val arguments = call.arguments as? Map filePath = (arguments?.get("filePath") as? String).toString() diff --git a/local_plugins/ota/lib/ota.dart b/local_plugins/ota/lib/ota.dart index 4df7c8d01..871fa4198 100644 --- a/local_plugins/ota/lib/ota.dart +++ b/local_plugins/ota/lib/ota.dart @@ -138,8 +138,8 @@ class Ota { _isEventListenerSet = true; } - Future searchDevices(String? filePath) { - return OtaPlatform.instance.searchDevices(filePath); + Future startUpgrading(String? filePath) { + return OtaPlatform.instance.startUpgrading(filePath); } Future onOtaClose() { diff --git a/local_plugins/ota/lib/ota_method_channel.dart b/local_plugins/ota/lib/ota_method_channel.dart index 1dffdee59..504acb9d6 100644 --- a/local_plugins/ota/lib/ota_method_channel.dart +++ b/local_plugins/ota/lib/ota_method_channel.dart @@ -10,9 +10,9 @@ class MethodChannelOta extends OtaPlatform { final methodChannel = const MethodChannel('ota'); @override - Future searchDevices(String? filePath) async { + Future startUpgrading(String? filePath) async { final version = await methodChannel.invokeMethod( - 'searchDevices', + 'startUpgrading', {'filePath': filePath}, // 传递参数 ); return version; diff --git a/local_plugins/ota/lib/ota_platform_interface.dart b/local_plugins/ota/lib/ota_platform_interface.dart index 6c9c739ed..369f2d8f0 100644 --- a/local_plugins/ota/lib/ota_platform_interface.dart +++ b/local_plugins/ota/lib/ota_platform_interface.dart @@ -23,7 +23,7 @@ abstract class OtaPlatform extends PlatformInterface { _instance = instance; } - Future searchDevices(String? filePath) { + Future startUpgrading(String? filePath) { throw UnimplementedError('platformVersion() has not been implemented.'); }