From 32c29fa045a4d538ed63c3f39409879dab8e84ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=8C=AF=E5=8D=87?= <359059686@qq.com> Date: Fri, 24 Oct 2025 16:55:16 +0800 Subject: [PATCH] =?UTF-8?q?fix=20:=20=E7=A7=BB=E9=99=A4=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 1 + build_flutter_app.dart | 30 ++++++++------- lib/app/core/services/sync_service.dart | 34 ++++++++--------- lib/app/core/services/upgrader_service.dart | 16 ++++---- .../enterprise_upload_controller.dart | 2 +- .../pages/enterprise_form_page.dart | 38 ------------------- .../pages/enterprise_upload_page.dart | 4 +- .../controllers/navigation_controller.dart | 1 - .../views/problem_upload_page.dart | 34 ----------------- 9 files changed, 44 insertions(+), 116 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f612255..976a735 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,6 +2,7 @@ "cSpell.words": [ "fenix", "Getx", + "Syncable", "tdesign", "usecase", "usecases" diff --git a/build_flutter_app.dart b/build_flutter_app.dart index 78f2b34..3c5c342 100644 --- a/build_flutter_app.dart +++ b/build_flutter_app.dart @@ -1,8 +1,10 @@ import 'dart:io'; import 'dart:convert'; +import 'package:flutter/foundation.dart'; + void main(List arguments) async { - print('🚀 开始构建Flutter Android应用...'); + debugPrint('🚀 开始构建Flutter Android应用...'); // 默认构建 ARM64 + ARM32(推荐) final targetPlatform = arguments.contains('--arm64-only') @@ -19,28 +21,28 @@ void main(List arguments) async { // 生成version.json文件 await generateVersionJson(apkPath, targetPlatform); - print('✅ 构建完成!'); - print('📦 APK位置: $apkPath'); + debugPrint('✅ 构建完成!'); + debugPrint('📦 APK位置: $apkPath'); } catch (e) { - print('❌ 构建过程中出现错误: $e'); + debugPrint('❌ 构建过程中出现错误: $e'); exit(1); } } Future buildFlutterApp(String targetPlatform) async { - print('📱 正在构建Flutter Android应用...'); - print('🎯 目标平台: $targetPlatform'); + debugPrint('📱 正在构建Flutter Android应用...'); + debugPrint('🎯 目标平台: $targetPlatform'); // 清理构建缓存 - print('🧹 清理构建缓存...'); + debugPrint('🧹 清理构建缓存...'); await runFlutterCommand(['clean']); // 获取pub依赖 - print('📦 获取依赖...'); + debugPrint('📦 获取依赖...'); await runFlutterCommand(['pub', 'get']); // 构建APK(指定目标平台) - print('🔨 构建Release APK...'); + debugPrint('🔨 构建Release APK...'); await runFlutterCommand([ 'build', 'apk', @@ -48,7 +50,7 @@ Future buildFlutterApp(String targetPlatform) async { '--target-platform=$targetPlatform', ]); - print('✅ Flutter应用构建成功!'); + debugPrint('✅ Flutter应用构建成功!'); // 根据目标平台生成对应的APK文件名 String apkName; @@ -71,7 +73,7 @@ Future runFlutterCommand(List args) async { } Future generateVersionJson(String apkPath, String targetPlatform) async { - print('📄 正在生成version.json文件...'); + debugPrint('📄 正在生成version.json文件...'); final apkFile = File(apkPath); String fileSize = '未知'; @@ -79,7 +81,7 @@ Future generateVersionJson(String apkPath, String targetPlatform) async { if (await apkFile.exists()) { final apkSize = await apkFile.length(); fileSize = '${(apkSize / (1024 * 1024)).toStringAsFixed(1)}MB'; - print('📦 APK文件大小: $fileSize'); + debugPrint('📦 APK文件大小: $fileSize'); } final now = DateTime.now(); @@ -102,7 +104,7 @@ Future generateVersionJson(String apkPath, String targetPlatform) async { const JsonEncoder.withIndent(' ').convert(versionInfo), ); - print('✅ version.json文件生成成功!'); + debugPrint('✅ version.json文件生成成功!'); } String getBuildNumber() { @@ -115,5 +117,5 @@ Future checkFlutterEnvironment() async { if (result.exitCode != 0) { throw Exception('Flutter环境检查失败'); } - print('✅ Flutter环境正常'); + debugPrint('✅ Flutter环境正常'); } diff --git a/lib/app/core/services/sync_service.dart b/lib/app/core/services/sync_service.dart index 25fbee9..5e6a80f 100644 --- a/lib/app/core/services/sync_service.dart +++ b/lib/app/core/services/sync_service.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:get/get.dart'; import 'package:problem_check_system/app/core/models/sync_status.dart'; import 'package:problem_check_system/app/core/repositories/syncable_repository.dart'; @@ -35,7 +36,7 @@ class SyncService extends GetxService { void registerRepository( SyncableRepository repository, ) { - print('[SyncService] Registering repository for type: $T'); + debugPrint('[SyncService] Registering repository for type: $T'); _repositories[T] = repository; } @@ -46,7 +47,7 @@ class SyncService extends GetxService { /// 1. **上传阶段**: 推送所有本地的待创建、待更新、待删除的记录。 /// 2. **下载阶段**: 为每个已注册的实体类型,拉取自上次同步以来的服务器更新。 Future performFullSync() async { - print('[SyncService] === Starting Full Sync Cycle ==='); + debugPrint('[SyncService] === Starting Full Sync Cycle ==='); // 阶段一: 上传本地所有待处理的更改 await _pushAllPendingChanges(); @@ -54,7 +55,7 @@ class SyncService extends GetxService { // 阶段二: 下载所有已注册的实体的服务器更新 await _pullAllServerUpdates(); - print('[SyncService] === Full Sync Cycle Finished ==='); + debugPrint('[SyncService] === Full Sync Cycle Finished ==='); } /// --- 私有辅助方法 --- /// @@ -62,18 +63,18 @@ class SyncService extends GetxService { /// **上传阶段** /// 获取所有本地待同步的项,并逐个进行同步。 Future _pushAllPendingChanges() async { - print('[SyncService] >> Phase 1: Pushing local changes...'); + debugPrint('[SyncService] >> Phase 1: Pushing local changes...'); // 注意: 您需要实现一个方法来获取所有 feature 的待同步项。 // 这里我们假设有一个 `_getAllPendingItems()` 方法。 final List allPendingItems = await _getAllPendingItems(); if (allPendingItems.isEmpty) { - print('[SyncService] No local changes to push.'); + debugPrint('[SyncService] No local changes to push.'); return; } - print( + debugPrint( '[SyncService] Found ${allPendingItems.length} pending items to push.', ); @@ -81,19 +82,19 @@ class SyncService extends GetxService { try { await _syncSingleItem(item); } catch (e) { - print( + debugPrint( '[SyncService] ERROR: Failed to push item ${item.id} of type ${item.runtimeType}. Error: $e', ); // 关键: 单个项目失败不应中断整个上传流程,继续尝试下一个。 } } - print('[SyncService] << Push phase completed.'); + debugPrint('[SyncService] << Push phase completed.'); } /// **下载阶段** /// 遍历所有已注册的仓库,并为每个仓库执行拉取操作。 Future _pullAllServerUpdates() async { - print('[SyncService] >> Phase 2: Pulling server updates...'); + debugPrint('[SyncService] >> Phase 2: Pulling server updates...'); // 记录本次同步周期开始的时间。如果某个类型的拉取成功,这将是它的新时间戳。 final DateTime syncCycleStartTime = DateTime.now().toUtc(); @@ -108,7 +109,7 @@ class SyncService extends GetxService { entityType, ); - print( + debugPrint( '[SyncService] Pulling updates for $entityType since: ${lastSyncTimestamp ?? 'the beginning'}', ); @@ -120,17 +121,17 @@ class SyncService extends GetxService { entityType, syncCycleStartTime, ); - print( + debugPrint( '[SyncService] Successfully pulled and updated timestamp for $entityType.', ); } catch (e) { - print( + debugPrint( '[SyncService] ERROR: Failed to pull updates for $entityType. Error: $e', ); // 关键: 一个类型的拉取失败不应中断其他类型的同步。 } } - print('[SyncService] << Pull phase completed.'); + debugPrint('[SyncService] << Pull phase completed.'); } /// 根据单个项目的同步状态,委托给对应的仓库执行操作。 @@ -138,13 +139,13 @@ class SyncService extends GetxService { final repository = _repositories[item.runtimeType]; if (repository == null) { - print( + debugPrint( '[SyncService] WARNING: No repository registered for type ${item.runtimeType}. Skipping item ${item.id}.', ); return; } - print( + debugPrint( '[SyncService] Pushing item ${item.id} (${item.runtimeType}) with status ${item.syncStatus.name}...', ); @@ -162,7 +163,6 @@ class SyncService extends GetxService { // 这不应该发生在待处理列表中,但为了安全起见,我们忽略它。 break; case SyncStatus.untracked: - // TODO: Handle this case. throw UnimplementedError(); } } @@ -178,7 +178,7 @@ class SyncService extends GetxService { // final enterprises = await enterpriseLocalDataSource.getPendingEnterprises(); // return [...problems, ...enterprises]; - print( + debugPrint( '[SyncService] WARNING: _getAllPendingItems() is not implemented. Returning empty list.', ); return []; // 返回空列表以防止错误 diff --git a/lib/app/core/services/upgrader_service.dart b/lib/app/core/services/upgrader_service.dart index dbbc56d..1ceac5a 100644 --- a/lib/app/core/services/upgrader_service.dart +++ b/lib/app/core/services/upgrader_service.dart @@ -77,23 +77,23 @@ class UpgraderService extends GetxService { if (dir == null) { Get.back(); // 关闭进度对话框 Get.snackbar('错误', '无法获取外部存储目录。'); - print('错误: getExternalStorageDirectory() 返回 null'); + Get.log('错误: getExternalStorageDirectory() 返回 null'); isDownloading.value = false; return; // 提前退出 } String savePath = '${dir.path}/app-release.apk'; - print('--- 调试信息 ---'); - print('目标下载路径: $savePath'); - print('--- 调试信息 ---'); + Get.log('--- 调试信息 ---'); + Get.log('目标下载路径: $savePath'); + Get.log('--- 调试信息 ---'); // 确保父目录存在 final file = File(savePath); if (!await file.parent.exists()) { await file.parent.create(recursive: true); - print('--- 调试信息 ---'); - print('已尝试创建父目录: ${file.parent.path}'); - print('--- 调试信息 ---'); + Get.log('--- 调试信息 ---'); + Get.log('已尝试创建父目录: ${file.parent.path}'); + Get.log('--- 调试信息 ---'); } await _dio.download( @@ -205,7 +205,7 @@ class UpgraderService extends GetxService { // 抽离出打开文件的逻辑 Future _openApkFile(String path) async { final result = await OpenFile.open(path); - print('OpenFile result: ${result.type}, message: ${result.message}'); + Get.log('OpenFile result: ${result.type}, message: ${result.message}'); if (result.type != ResultType.done) { Get.snackbar('安装失败', '无法启动安装程序: ${result.message}'); } diff --git a/lib/app/features/enterprise/presentation/controllers/enterprise_upload_controller.dart b/lib/app/features/enterprise/presentation/controllers/enterprise_upload_controller.dart index 76d9c29..3dd4afc 100644 --- a/lib/app/features/enterprise/presentation/controllers/enterprise_upload_controller.dart +++ b/lib/app/features/enterprise/presentation/controllers/enterprise_upload_controller.dart @@ -69,7 +69,7 @@ class EnterpriseUploadController extends GetxController { return; } // 在这里执行实际的上传业务逻辑... - print('正在上传 ${selectedEnterprises.length} 个企业...'); + Get.log('正在上传 ${selectedEnterprises.length} 个企业...'); // 操作成功后,返回 true 通知上一个页面刷新 Get.back(result: true); diff --git a/lib/app/features/enterprise/presentation/pages/enterprise_form_page.dart b/lib/app/features/enterprise/presentation/pages/enterprise_form_page.dart index 9178729..5501950 100644 --- a/lib/app/features/enterprise/presentation/pages/enterprise_form_page.dart +++ b/lib/app/features/enterprise/presentation/pages/enterprise_form_page.dart @@ -29,44 +29,6 @@ class EnterpriseFormPage extends GetView { ); } - // 将 controller 传进来以获取动态标题 - PreferredSizeWidget _buildAppBar() { - return AppBar( - // ... 其他 AppBar 属性 - // 使用 Obx 来监听 pageTitle 的变化 - title: Obx( - () => Text( - controller.pageTitle.value, - style: TextStyle( - fontSize: 18.sp, - color: Colors.white, - fontWeight: FontWeight.bold, - ), - ), - ), - leading: IconButton( - icon: Icon( - Icons.arrow_back_ios_new_rounded, - size: 24.sp, - color: Colors.white, - ), - onPressed: () => Get.back(), - ), - backgroundColor: Colors.transparent, - flexibleSpace: Container( - decoration: const BoxDecoration( - gradient: LinearGradient( - colors: [Color(0xFF418CFC), Color(0xFF3DBFFC)], - begin: Alignment.centerLeft, - end: Alignment.centerRight, - ), - ), - ), - elevation: 0, - centerTitle: true, - ); - } - // 构建底部的取消和确定按钮 Widget _buildBottomButtons() { return Container( diff --git a/lib/app/features/enterprise/presentation/pages/enterprise_upload_page.dart b/lib/app/features/enterprise/presentation/pages/enterprise_upload_page.dart index 5cb996a..708d8d0 100644 --- a/lib/app/features/enterprise/presentation/pages/enterprise_upload_page.dart +++ b/lib/app/features/enterprise/presentation/pages/enterprise_upload_page.dart @@ -16,9 +16,7 @@ class EnterpriseUploadPage extends GetView { selectedCount: 10, selectedAll: true, buttonVisible: false, - onButtonPressed: () { - print("object"); - }, + onButtonPressed: () {}, ), body: _buildEnterpriseList(), bottomSheet: Container( diff --git a/lib/app/features/navigation/presentation/controllers/navigation_controller.dart b/lib/app/features/navigation/presentation/controllers/navigation_controller.dart index 8223be3..f38a22e 100644 --- a/lib/app/features/navigation/presentation/controllers/navigation_controller.dart +++ b/lib/app/features/navigation/presentation/controllers/navigation_controller.dart @@ -1,4 +1,3 @@ -import 'package:curved_navigation_bar/curved_navigation_bar.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; diff --git a/lib/app/features/problem/presentation/views/problem_upload_page.dart b/lib/app/features/problem/presentation/views/problem_upload_page.dart index 1cb0ae9..22bbc31 100644 --- a/lib/app/features/problem/presentation/views/problem_upload_page.dart +++ b/lib/app/features/problem/presentation/views/problem_upload_page.dart @@ -23,40 +23,6 @@ class ProblemUploadPage extends GetView { ); } - PreferredSizeWidget _buildAppBar() { - return AppBar( - title: Obx(() { - final selectedCount = controller.selectedCount; - return Text('已选择$selectedCount项'); - }), - centerTitle: true, - // leading: IconButton( - // icon: Icon(Icons.close), - // onPressed: () { - // Get.back(); - // controller.loadProblems(); - // }, - // ), - actions: [ - Obx( - () => TextButton( - onPressed: controller.unUploadedProblems.isNotEmpty - ? controller.selectAll - : null, - child: Text( - controller.allSelected.value ? '取消全选' : '全选', - style: TextStyle( - color: controller.unUploadedProblems.isNotEmpty - ? Colors.blue - : Colors.grey, - ), - ), - ), - ), - ], - ); - } - Widget _buildBody() { return Obx(() { if (controller.unUploadedProblems.isEmpty) {