feat: update app icons and refactor home top professionals section to display dynamic agent profiles.
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 258 KiB After Width: | Height: | Size: 276 KiB |
|
Before Width: | Height: | Size: 159 KiB After Width: | Height: | Size: 188 KiB |
|
Before Width: | Height: | Size: 736 B After Width: | Height: | Size: 627 B |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 981 B |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.0 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
@@ -5,6 +5,8 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import 'package:real_estate_mobile/core/constants/app_colors.dart';
|
||||
import 'package:real_estate_mobile/core/widgets/s3_image.dart';
|
||||
import 'package:real_estate_mobile/features/agents/data/models/agent_profile.dart';
|
||||
import 'package:real_estate_mobile/features/agents/presentation/providers/agents_provider.dart';
|
||||
import 'package:real_estate_mobile/features/home/data/models/landing_page_content.dart';
|
||||
import 'package:real_estate_mobile/features/home/presentation/providers/home_provider.dart';
|
||||
|
||||
@@ -64,14 +66,16 @@ class _TopProfessionalsSectionState
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// CMS data for everything (title, CTA, agents, lenders)
|
||||
// CMS data for title/CTA text only
|
||||
final homeState = ref.watch(homeProvider);
|
||||
final cmsContent = homeState.content?.topProfessionals ?? _defaultCmsContent;
|
||||
|
||||
// Use CMS agents/lenders list based on active tab
|
||||
// Dynamic data from database (top-rated agents/lenders, matching web)
|
||||
final profState = ref.watch(topProfessionalsProvider);
|
||||
final activeList = _activeTab == 'agents'
|
||||
? cmsContent.agents
|
||||
: cmsContent.lenders;
|
||||
? profState.agents
|
||||
: profState.lenders;
|
||||
final isLoading = profState.isLoading || homeState.isLoading;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
@@ -96,7 +100,7 @@ class _TopProfessionalsSectionState
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Content
|
||||
if (homeState.isLoading)
|
||||
if (isLoading)
|
||||
_buildShimmerCards()
|
||||
else if (activeList.isEmpty)
|
||||
_buildEmptyState(_activeTab)
|
||||
@@ -118,7 +122,7 @@ class _TopProfessionalsSectionState
|
||||
left: index == 0 ? 0 : 8,
|
||||
right: index == activeList.length - 1 ? 0 : 8,
|
||||
),
|
||||
child: _buildCmsProfessionalCard(activeList[index], index: index),
|
||||
child: _buildProfessionalCard(activeList[index], index: index),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -279,9 +283,14 @@ class _TopProfessionalsSectionState
|
||||
);
|
||||
}
|
||||
|
||||
// -- Professional Card using CMS ProfessionalItem data --
|
||||
Widget _buildCmsProfessionalCard(ProfessionalItem item, {int index = 0}) {
|
||||
final imageUrl = item.imageUrl;
|
||||
// -- Professional Card using dynamic AgentProfile data (matching web) --
|
||||
Widget _buildProfessionalCard(AgentProfile agent, {int index = 0}) {
|
||||
final imageUrl = agent.avatarUrl ?? '';
|
||||
final expertiseTags = agent.specializations;
|
||||
final experience = agent.experienceText;
|
||||
final locationText = agent.location;
|
||||
final subtitle = agent.agentType != null ? '(${agent.agentType!.name})' : '';
|
||||
final rating = agent.averageRating ?? 5.0;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -323,7 +332,7 @@ class _TopProfessionalsSectionState
|
||||
children: [
|
||||
// Name
|
||||
Text(
|
||||
item.name,
|
||||
agent.fullName,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
@@ -334,10 +343,10 @@ class _TopProfessionalsSectionState
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// Subtitle
|
||||
if (item.subtitle.isNotEmpty)
|
||||
// Subtitle (agent type)
|
||||
if (subtitle.isNotEmpty)
|
||||
Text(
|
||||
item.subtitle,
|
||||
subtitle,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 10,
|
||||
@@ -350,6 +359,7 @@ class _TopProfessionalsSectionState
|
||||
const SizedBox(height: 4),
|
||||
|
||||
// Verified badge
|
||||
if (agent.isVerified)
|
||||
Row(
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
@@ -377,7 +387,7 @@ class _TopProfessionalsSectionState
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// Location
|
||||
if (item.location.isNotEmpty) ...[
|
||||
if (locationText.isNotEmpty) ...[
|
||||
const Text(
|
||||
'Location:',
|
||||
style: TextStyle(
|
||||
@@ -403,7 +413,7 @@ class _TopProfessionalsSectionState
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
item.location,
|
||||
locationText,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 10,
|
||||
@@ -419,7 +429,7 @@ class _TopProfessionalsSectionState
|
||||
],
|
||||
|
||||
// Expertise tags
|
||||
if (item.expertise.isNotEmpty) ...[
|
||||
if (expertiseTags.isNotEmpty) ...[
|
||||
const Text(
|
||||
'Expertise:',
|
||||
style: TextStyle(
|
||||
@@ -433,7 +443,7 @@ class _TopProfessionalsSectionState
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 6,
|
||||
children: item.expertise
|
||||
children: expertiseTags
|
||||
.take(6)
|
||||
.map((tag) => _buildTag(tag))
|
||||
.toList(),
|
||||
@@ -442,7 +452,7 @@ class _TopProfessionalsSectionState
|
||||
],
|
||||
|
||||
// Experience
|
||||
if (item.experience.isNotEmpty) ...[
|
||||
if (experience.isNotEmpty) ...[
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
@@ -456,7 +466,7 @@ class _TopProfessionalsSectionState
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: item.experience,
|
||||
text: experience,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 14,
|
||||
@@ -478,7 +488,7 @@ class _TopProfessionalsSectionState
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 4),
|
||||
child: Icon(
|
||||
i < item.rating.round()
|
||||
i < rating.round()
|
||||
? Icons.star_rounded
|
||||
: Icons.star_outline_rounded,
|
||||
color: const Color(0xFFE5A625),
|
||||
@@ -493,9 +503,9 @@ class _TopProfessionalsSectionState
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildShimmerCards() {
|
||||
return SizedBox(
|
||||
height: 540,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:real_estate_mobile/config/app_config.dart';
|
||||
import 'package:real_estate_mobile/core/network/api_client.dart';
|
||||
import 'package:real_estate_mobile/core/storage/secure_storage.dart';
|
||||
import 'package:real_estate_mobile/features/messaging/data/models/message.dart';
|
||||
import 'package:real_estate_mobile/features/support_chat/data/models/support_chat_models.dart';
|
||||
@@ -144,12 +145,31 @@ class SocketService {
|
||||
}
|
||||
|
||||
Future<void> _reconnectWithFreshToken() async {
|
||||
// Wait briefly for any in-flight REST token refresh to complete
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
|
||||
final token = await SecureStorage.getAccessToken();
|
||||
if (token != null && token != _currentToken) {
|
||||
_currentToken = token;
|
||||
_socket?.io.options?['auth'] = {'token': token};
|
||||
_socket?.connect();
|
||||
if (token == null) return;
|
||||
|
||||
// If token hasn't changed, try triggering a refresh via a lightweight API call
|
||||
if (token == _currentToken) {
|
||||
try {
|
||||
// Make a lightweight call that triggers the API client's 401 interceptor
|
||||
// which auto-refreshes the token
|
||||
final dio = ApiClient.instance.dio;
|
||||
await dio.get('/auth/me');
|
||||
final refreshedToken = await SecureStorage.getAccessToken();
|
||||
if (refreshedToken == null || refreshedToken == _currentToken) return;
|
||||
_currentToken = refreshedToken;
|
||||
} catch (_) {
|
||||
return; // Token refresh failed — user will need to re-login
|
||||
}
|
||||
} else {
|
||||
_currentToken = token;
|
||||
}
|
||||
|
||||
_socket?.io.options?['auth'] = {'token': _currentToken};
|
||||
_socket?.connect();
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
|
||||
@@ -97,7 +97,7 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
final currentMessages =
|
||||
List<ChatMessage>.from(state.messages[convId] ?? []);
|
||||
|
||||
// Avoid duplicates
|
||||
// Avoid duplicates (broadcast may arrive after ack for sender's own message)
|
||||
if (currentMessages.any((m) => m.id == message.id)) return;
|
||||
|
||||
currentMessages.insert(0, message);
|
||||
@@ -105,12 +105,22 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
Map<String, List<ChatMessage>>.from(state.messages)
|
||||
..[convId] = currentMessages;
|
||||
|
||||
// Show friendly preview for non-text messages (matching web)
|
||||
String previewText = message.content;
|
||||
if (message.messageType == MessageType.image) {
|
||||
previewText = 'Sent an image';
|
||||
} else if (message.messageType == MessageType.file) {
|
||||
previewText = 'Sent a file';
|
||||
} else if (_isGifUrl(message.content)) {
|
||||
previewText = 'GIF';
|
||||
}
|
||||
|
||||
// Update conversation's last message and unread count
|
||||
final updatedConversations = state.conversations.map((c) {
|
||||
if (c.id == convId) {
|
||||
final isActive = state.activeConversationId == convId;
|
||||
return c.copyWith(
|
||||
lastMessageText: message.content,
|
||||
lastMessageText: previewText,
|
||||
lastMessageAt: message.createdAt,
|
||||
unreadCount: isActive ? c.unreadCount : c.unreadCount + 1,
|
||||
);
|
||||
@@ -155,6 +165,59 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
}).toList();
|
||||
state = state.copyWith(conversations: updatedConversations);
|
||||
}));
|
||||
|
||||
// Reconnection: re-join active conversation room and catch up missed messages
|
||||
_subscriptions.add(_socket.onConnectionChange.listen((connected) {
|
||||
if (!mounted || !connected) return;
|
||||
final activeConvId = state.activeConversationId;
|
||||
if (activeConvId != null) {
|
||||
_rejoinAndCatchUp(activeConvId);
|
||||
}
|
||||
// Refresh conversation list to catch any missed updates
|
||||
loadConversations();
|
||||
}));
|
||||
}
|
||||
|
||||
/// Re-join socket room and fetch missed messages after reconnection (matching web)
|
||||
Future<void> _rejoinAndCatchUp(String conversationId, {int attempt = 1}) async {
|
||||
try {
|
||||
await _socket.joinConversation(conversationId);
|
||||
} catch (_) {
|
||||
if (attempt < 3 && mounted && state.activeConversationId == conversationId) {
|
||||
await Future.delayed(Duration(seconds: attempt));
|
||||
return _rejoinAndCatchUp(conversationId, attempt: attempt + 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch recent messages to catch any missed during disconnect
|
||||
if (!mounted || state.activeConversationId != conversationId) return;
|
||||
try {
|
||||
final result = await _repository.getMessages(conversationId, page: 1);
|
||||
final recentMessages = result.messages.reversed.toList();
|
||||
final currentMessages = List<ChatMessage>.from(state.messages[conversationId] ?? []);
|
||||
final existingIds = currentMessages.map((m) => m.id).toSet();
|
||||
final newMessages = recentMessages.where((m) => !existingIds.contains(m.id)).toList();
|
||||
|
||||
if (newMessages.isNotEmpty && mounted) {
|
||||
currentMessages.insertAll(0, newMessages);
|
||||
// Sort newest first
|
||||
currentMessages.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
final updatedMessages = Map<String, List<ChatMessage>>.from(state.messages)
|
||||
..[conversationId] = currentMessages;
|
||||
state = state.copyWith(messages: updatedMessages);
|
||||
}
|
||||
} catch (e) {
|
||||
_log.e('Failed to catch up messages after reconnect', error: e);
|
||||
}
|
||||
}
|
||||
|
||||
static bool _isGifUrl(String text) {
|
||||
final lower = text.trim().toLowerCase();
|
||||
return lower.endsWith('.gif') ||
|
||||
lower.contains('giphy.com/') ||
|
||||
lower.contains('giphy.gif') ||
|
||||
lower.contains('tenor.com/');
|
||||
}
|
||||
|
||||
/// Update online status for a user across all conversations (matching web)
|
||||
@@ -320,12 +383,22 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
Map<String, List<ChatMessage>>.from(state.messages)
|
||||
..[conversationId] = messagesAfterSend;
|
||||
|
||||
// Update conversation's last message
|
||||
// Update conversation's last message with friendly preview
|
||||
final sent = realMessage;
|
||||
String sentPreview = sent.content;
|
||||
if (sent.messageType == MessageType.image) {
|
||||
sentPreview = 'Sent an image';
|
||||
} else if (sent.messageType == MessageType.file) {
|
||||
sentPreview = 'Sent a file';
|
||||
} else if (_isGifUrl(sent.content)) {
|
||||
sentPreview = 'GIF';
|
||||
}
|
||||
|
||||
final updatedConversations = state.conversations.map((c) {
|
||||
if (c.id == conversationId) {
|
||||
return c.copyWith(
|
||||
lastMessageText: realMessage!.content,
|
||||
lastMessageAt: realMessage.createdAt,
|
||||
lastMessageText: sentPreview,
|
||||
lastMessageAt: sent.createdAt,
|
||||
);
|
||||
}
|
||||
return c;
|
||||
|
||||