From 89dbdb55b8ee01c06831148784cee1fefcdedb28 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 4 Mar 2026 23:31:35 -0800 Subject: [PATCH] =?UTF-8?q?fix(admin-app):=20fix=20dynamic=E2=86=92int=20t?= =?UTF-8?q?ype=20errors=20in=20service=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - notification_service: cast total/unreadCount in NotificationListResponse, cast count in getUnreadCount/getAnnouncementUnreadCount (Future) - auth_service: fix unsafe (value ?? 300) as int → (value as int?) ?? 300 Co-Authored-By: Claude Sonnet 4.6 --- frontend/admin-app/lib/core/services/auth_service.dart | 2 +- .../admin-app/lib/core/services/notification_service.dart | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/admin-app/lib/core/services/auth_service.dart b/frontend/admin-app/lib/core/services/auth_service.dart index 6d8ae7f..a3df8ac 100644 --- a/frontend/admin-app/lib/core/services/auth_service.dart +++ b/frontend/admin-app/lib/core/services/auth_service.dart @@ -28,7 +28,7 @@ class AuthService { }); final data = response.data is Map ? response.data : {}; final inner = data['data'] ?? data; - return (inner is Map) ? (inner['expiresIn'] ?? 300) as int : 300; + return (inner is Map) ? (inner['expiresIn'] as int?) ?? 300 : 300; } catch (e) { debugPrint('[AuthService] sendSmsCode 失败: $e'); rethrow; diff --git a/frontend/admin-app/lib/core/services/notification_service.dart b/frontend/admin-app/lib/core/services/notification_service.dart index cbcb3c7..8ae3417 100644 --- a/frontend/admin-app/lib/core/services/notification_service.dart +++ b/frontend/admin-app/lib/core/services/notification_service.dart @@ -115,8 +115,8 @@ class NotificationListResponse { []; return NotificationListResponse( notifications: list, - total: data['total'] ?? list.length, - unreadCount: data['unreadCount'] ?? 0, + total: (data['total'] as int?) ?? list.length, + unreadCount: (data['unreadCount'] as int?) ?? 0, ); } } @@ -162,7 +162,7 @@ class NotificationService { try { final response = await _apiClient.get('/api/v1/notifications/unread-count'); final data = response.data is Map ? response.data : {}; - return data['data']?['count'] ?? data['count'] ?? 0; + return (data['data']?['count'] as int?) ?? (data['count'] as int?) ?? 0; } catch (e) { debugPrint('[NotificationService] 获取未读数量失败: $e'); return 0; @@ -205,7 +205,7 @@ class NotificationService { try { final response = await _apiClient.get('/api/v1/announcements/unread-count'); final data = response.data is Map ? response.data : {}; - return data['data']?['count'] ?? data['count'] ?? 0; + return (data['data']?['count'] as int?) ?? (data['count'] as int?) ?? 0; } catch (e) { debugPrint('[NotificationService] 获取公告未读数失败: $e'); return 0;