refactor: update agent and lender filtering logic to categorize profiles by type ID

This commit is contained in:
pradeepkumar
2026-03-30 14:58:09 +05:30
parent d507a52b87
commit b3905865d6

View File

@@ -64,54 +64,56 @@ class TopProfessionalsNotifier extends StateNotifier<TopProfessionalsState> {
final agentTypes = await _repository.getAgentTypes();
state = state.copyWith(agentTypes: agentTypes);
// Find agent and lender type IDs by name
String? agentTypeId;
// Find lender type ID
String? lenderTypeId;
final nonLenderTypeIds = <String>[];
for (final type in agentTypes) {
final name = type.name.toLowerCase();
if (name.contains('lender') || name.contains('lending')) {
lenderTypeId = type.id;
} else if (name.contains('professional') ||
name.contains('agent') ||
name.contains('realtor') ||
name.contains('broker')) {
agentTypeId = type.id;
} else {
nonLenderTypeIds.add(type.id);
}
}
// If no specific agent type found, use first type as agents
if (agentTypeId == null && agentTypes.isNotEmpty) {
agentTypeId = agentTypes.first.id;
// Look for lender in remaining
for (final type in agentTypes) {
if (type.id != agentTypeId) {
lenderTypeId = type.id;
break;
}
}
}
// Fetch agents and lenders in parallel
final results = await Future.wait([
_repository.searchAgents(
agentTypeId: agentTypeId,
// Fetch agents (all non-lender types) and lenders in parallel
final agentsFuture = _repository.searchAgents(
limit: 10,
sortBy: 'averageRating',
sortOrder: 'desc',
),
if (lenderTypeId != null)
_repository.searchAgents(
);
final lendersFuture = lenderTypeId != null
? _repository.searchAgents(
agentTypeId: lenderTypeId,
limit: 10,
sortBy: 'averageRating',
sortOrder: 'desc',
),
]);
)
: null;
final agentsResult = await agentsFuture;
final lendersResult = lendersFuture != null ? await lendersFuture : null;
// Split: agents = non-lender profiles, lenders = lender profiles
final allAgents = agentsResult.data;
List<AgentProfile> agents;
List<AgentProfile> lenders;
if (lenderTypeId != null) {
agents = allAgents
.where((a) => a.agentType?.id != lenderTypeId)
.toList();
lenders = lendersResult?.data ??
allAgents.where((a) => a.agentType?.id == lenderTypeId).toList();
} else {
agents = allAgents;
lenders = [];
}
state = state.copyWith(
agents: results[0].data,
lenders: results.length > 1 ? results[1].data : [],
agents: agents,
lenders: lenders,
isLoading: false,
);
} catch (e) {