From 0be0da7c575e63bc1e93b66222969eaa312d6521 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Wed, 6 May 2026 15:35:34 +0530 Subject: [PATCH] refactor: improve error message handling in profile settings and add width constraints to agent tag chips --- .../screens/agent_home_screen.dart | 110 ++++++++++-------- .../widgets/profile_settings_tab.dart | 8 +- 2 files changed, 70 insertions(+), 48 deletions(-) diff --git a/lib/features/agents/presentation/screens/agent_home_screen.dart b/lib/features/agents/presentation/screens/agent_home_screen.dart index 864051e..a58ecc1 100644 --- a/lib/features/agents/presentation/screens/agent_home_screen.dart +++ b/lib/features/agents/presentation/screens/agent_home_screen.dart @@ -1113,54 +1113,70 @@ class _AgentHomeContentState extends ConsumerState<_AgentHomeContent> { isExpanded ? tags : tags.take(initialCount).toList(); final remaining = tags.length - initialCount; - return Wrap( - spacing: 8, - runSpacing: 8, - children: [ - ...displayTags.map((tag) => Container( - padding: - const EdgeInsets.symmetric(horizontal: 12, vertical: 6), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15), - border: - Border.all(color: AppColors.primaryDark, width: 0.7), + // Cap each chip's width so long taglines wrap inside the chip instead + // of overflowing the Wrap's row and clipping behind ancestor bounds. + return LayoutBuilder( + builder: (ctx, constraints) { + final maxChipWidth = constraints.maxWidth.isFinite + ? constraints.maxWidth + : MediaQuery.of(ctx).size.width - 32; + return Wrap( + spacing: 8, + runSpacing: 8, + children: [ + ...displayTags.map((tag) => ConstrainedBox( + constraints: BoxConstraints(maxWidth: maxChipWidth), + child: Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 6), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + border: Border.all( + color: AppColors.primaryDark, width: 0.7), + ), + child: Text( + tag, + softWrap: true, + style: const TextStyle( + fontFamily: 'SourceSerif4', + fontSize: 14, + fontWeight: FontWeight.w500, + color: AppColors.primaryDark), + ), + ), + )), + if (remaining > 0) + GestureDetector( + onTap: () { + setState(() { + if (isExpanded) { + _expandedTagSections.remove(sectionKey); + } else { + _expandedTagSections.add(sectionKey); + } + }); + }, + behavior: HitTestBehavior.opaque, + child: Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 6), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + border: Border.all( + color: AppColors.primaryDark, width: 0.1), + ), + child: Text( + isExpanded ? 'Show Less' : '+$remaining More', + style: const TextStyle( + fontFamily: 'SourceSerif4', + fontSize: 15, + fontWeight: FontWeight.w300, + color: AppColors.primaryDark)), + ), ), - child: Text(tag, - style: const TextStyle( - fontFamily: 'SourceSerif4', - fontSize: 14, - fontWeight: FontWeight.w500, - color: AppColors.primaryDark)), - )), - if (remaining > 0) - GestureDetector( - onTap: () { - setState(() { - if (isExpanded) { - _expandedTagSections.remove(sectionKey); - } else { - _expandedTagSections.add(sectionKey); - } - }); - }, - behavior: HitTestBehavior.opaque, - child: Container( - padding: - const EdgeInsets.symmetric(horizontal: 12, vertical: 6), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15), - border: Border.all(color: AppColors.primaryDark, width: 0.1), - ), - child: Text( - isExpanded ? 'Show Less' : '+$remaining More', - style: const TextStyle( - fontFamily: 'SourceSerif4', - fontSize: 15, - fontWeight: FontWeight.w300, - color: AppColors.primaryDark)), - ), - ), - ], + ], + ); + }, ); } diff --git a/lib/features/profile/presentation/widgets/profile_settings_tab.dart b/lib/features/profile/presentation/widgets/profile_settings_tab.dart index 489adc1..26e4e0c 100644 --- a/lib/features/profile/presentation/widgets/profile_settings_tab.dart +++ b/lib/features/profile/presentation/widgets/profile_settings_tab.dart @@ -6,6 +6,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:image_picker/image_picker.dart'; import 'package:real_estate_mobile/core/constants/app_colors.dart'; +import 'package:real_estate_mobile/core/network/api_exceptions.dart'; import 'package:real_estate_mobile/core/utils/image_url_resolver.dart'; import 'package:real_estate_mobile/core/widgets/s3_image.dart'; import 'package:real_estate_mobile/features/profile/data/profile_repository.dart'; @@ -500,7 +501,12 @@ class _ChangeEmailSheetState extends State<_ChangeEmailSheet> { if (!mounted) return; setState(() { _submitting = false; - _localError = e.toString().replaceFirst('Exception: ', ''); + // ApiException carries the backend's message verbatim + // (e.g. "Incorrect password", "Email is already in use"). + // Fall back to a generic message for unexpected error types. + _localError = e is ApiException + ? e.message + : 'Something went wrong. Please try again.'; }); } }