From 5f4782434a4be9b869a777b3b5b931aad3401c4e Mon Sep 17 00:00:00 2001 From: "Mr.Jebelli" Date: Sun, 21 Jun 2026 10:16:52 +0330 Subject: [PATCH] exclude trend/tech/startup from UUID short-circuit + move category badge below date" --- .../home_widget_repository.dart | 48 +++++++++-- .../infography_details.dart | 79 ++++++++++--------- 2 files changed, 84 insertions(+), 43 deletions(-) diff --git a/lib/services/app_home_widget/home_widget_repository.dart b/lib/services/app_home_widget/home_widget_repository.dart index 1a925cc..ff4b161 100644 --- a/lib/services/app_home_widget/home_widget_repository.dart +++ b/lib/services/app_home_widget/home_widget_repository.dart @@ -21,16 +21,16 @@ class HomeWidgetRepository { /// Helper method to safely parse ID from notification data static int? _safeParseId(dynamic id) { if (id == null) return null; - + String idStr = id.toString().trim(); - + // Check if string contains "null" or is empty - if (idStr.isEmpty || - idStr == 'null' || + if (idStr.isEmpty || + idStr == 'null' || idStr.toLowerCase().contains('null')) { return null; } - + try { return int.parse(idStr); } catch (e) { @@ -41,6 +41,19 @@ class HomeWidgetRepository { } } + /// True when [id] looks like a UUID (e.g. cdaa8830-d03d-420e-9921-4997a44457e9), + /// which means the notification refers to a content from the new + /// content-service (UUID-based) rather than a legacy int-id record. + static bool _isUuid(dynamic id) { + if (id == null) return false; + final s = id.toString().trim(); + // Loose check — 8-4-4-4-12 hex with dashes, length 36. + final re = RegExp( + r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$', + ); + return re.hasMatch(s); + } + static Future fetchWidget() async { // RequestService.token = await StorageService.getValue(key: 'token'); final service = RequestService( @@ -223,7 +236,30 @@ class HomeWidgetRepository { if (localData.link.toString().isEmpty || localData.link.toString() == "null") { - if (localData.type == null || localData.type!.isEmpty) { + // ---------------- UUID short-circuit ---------------- + // Content from the new content-service uses UUIDs (e.g. cdaa8830-…). + // The legacy routes below assume int IDs, so for any UUID we route + // straight to InfographyDetails which knows how to fetch by UUID + // from content-service. + // + // Exception: trend / technology / startup intentionally render in + // their dedicated web apps (trend.didvan.app, tech.didvan.app, + // startup.didvan.app) — for those types we fall through to the + // legacy switch below so the URL is constructed and opened in a + // WebView, even when the id is a UUID. + const _webViewTypes = {'trend', 'technology', 'startup'}; + final _isWebViewType = _webViewTypes.contains(localData.type); + if (_isUuid(localData.id) && !_isWebViewType) { + if (kDebugMode) { + print("UUID detected — routing to InfographyDetails for " + "type='${localData.type}' id=${localData.id}"); + } + route = Routes.infographyDetails; + args = { + 'contentUuid': localData.id, + 'link': localData.link, + }; + } else if (localData.type == null || localData.type!.isEmpty) { if (kDebugMode) { print("=== NAVIGATION ABORTED ==="); print("Reason: Notification type is null or empty"); diff --git a/lib/views/home/infography/infography_details/infography_details.dart b/lib/views/home/infography/infography_details/infography_details.dart index 0835275..df5bfe3 100644 --- a/lib/views/home/infography/infography_details/infography_details.dart +++ b/lib/views/home/infography/infography_details/infography_details.dart @@ -219,43 +219,6 @@ class _InfographyDetailsState extends State { ), ), - // === badge دسته‌بندی روی تصویر === - if (_categoryLabel.isNotEmpty) - Positioned( - top: 16, - left: 16, - child: Container( - padding: const EdgeInsets.symmetric( - horizontal: 12, vertical: 6), - decoration: BoxDecoration( - color: const Color.fromARGB(255, 230, 242, 246), - borderRadius: BorderRadius.circular(16), - ), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - SvgPicture.asset( - _getCategoryIcon(_categoryLabel), - height: 16, - width: 16, - color: - const Color.fromARGB(255, 25, 93, 128), - ), - const SizedBox(width: 6), - DidvanText( - _categoryLabel, - style: theme.textTheme.bodySmall?.copyWith( - color: - const Color.fromARGB(255, 25, 93, 128), - fontWeight: FontWeight.bold, - fontSize: 12, - ), - ), - ], - ), - ), - ), - // === کارت سفید روی تصویر، لبه‌ی بالای آن «صاف» === Container( margin: EdgeInsets.only(top: imageHeight - overlap), @@ -310,6 +273,48 @@ class _InfographyDetailsState extends State { ), ), + // === badge دسته‌بندی (زیر تاریخ، به‌جای روی عکس) === + if (_categoryLabel.isNotEmpty) + Padding( + padding: const EdgeInsets.only( + left: 16, right: 16, top: 8), + child: Align( + alignment: AlignmentDirectional.centerStart, + child: Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 6), + decoration: BoxDecoration( + color: const Color.fromARGB( + 255, 230, 242, 246), + borderRadius: BorderRadius.circular(16), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + SvgPicture.asset( + _getCategoryIcon(_categoryLabel), + height: 16, + width: 16, + color: const Color.fromARGB( + 255, 25, 93, 128), + ), + const SizedBox(width: 6), + DidvanText( + _categoryLabel, + style: theme.textTheme.bodySmall + ?.copyWith( + color: const Color.fromARGB( + 255, 25, 93, 128), + fontWeight: FontWeight.bold, + fontSize: 12, + ), + ), + ], + ), + ), + ), + ), + // خلاصه/توضیحات if ((_description ?? '').isNotEmpty) ...[ const SizedBox(height: 16),