feat: Implement initial filtering for agent search from the home screen, enable footer navigation, and add provider stability checks.
This commit is contained in:
@@ -80,12 +80,14 @@ class SearchAgentsNotifier extends StateNotifier<SearchAgentsState> {
|
||||
_repository.getAgentTypes(),
|
||||
_repository.getFilterableFields(),
|
||||
]);
|
||||
if (!mounted) return;
|
||||
state = state.copyWith(
|
||||
agentTypes: results[0] as List<AgentType>,
|
||||
filterFields: results[1] as List<FilterableField>,
|
||||
);
|
||||
await _fetchAgents(page: 1);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
state = state.copyWith(isLoading: false, error: e.toString());
|
||||
}
|
||||
}
|
||||
@@ -99,7 +101,7 @@ class SearchAgentsNotifier extends StateNotifier<SearchAgentsState> {
|
||||
limit: 10,
|
||||
filters: state.activeFilters.isNotEmpty ? state.activeFilters : null,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
state = state.copyWith(
|
||||
agents: append ? [...state.agents, ...response.data] : response.data,
|
||||
currentPage: response.page,
|
||||
@@ -108,6 +110,7 @@ class SearchAgentsNotifier extends StateNotifier<SearchAgentsState> {
|
||||
isLoadingMore: false,
|
||||
);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
isLoadingMore: false,
|
||||
|
||||
@@ -11,8 +11,17 @@ import 'package:real_estate_mobile/features/agents/presentation/widgets/agent_fi
|
||||
|
||||
class AgentSearchScreen extends ConsumerStatefulWidget {
|
||||
final String? initialQuery;
|
||||
final String? initialAgentTypeId;
|
||||
final String? initialLocation;
|
||||
final String? initialCategory;
|
||||
|
||||
const AgentSearchScreen({super.key, this.initialQuery});
|
||||
const AgentSearchScreen({
|
||||
super.key,
|
||||
this.initialQuery,
|
||||
this.initialAgentTypeId,
|
||||
this.initialLocation,
|
||||
this.initialCategory,
|
||||
});
|
||||
|
||||
@override
|
||||
ConsumerState<AgentSearchScreen> createState() => _AgentSearchScreenState();
|
||||
@@ -28,14 +37,31 @@ class _AgentSearchScreenState extends ConsumerState<AgentSearchScreen> {
|
||||
_searchController = TextEditingController(text: widget.initialQuery ?? '');
|
||||
_scrollController.addListener(_onScroll);
|
||||
|
||||
// Trigger initial search if query provided
|
||||
if (widget.initialQuery != null && widget.initialQuery!.isNotEmpty) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ref
|
||||
.read(searchAgentsProvider.notifier)
|
||||
.search(widget.initialQuery!);
|
||||
});
|
||||
}
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final notifier = ref.read(searchAgentsProvider.notifier);
|
||||
|
||||
// Apply initial agent type filter if provided
|
||||
if (widget.initialAgentTypeId != null) {
|
||||
notifier.filterByAgentType(widget.initialAgentTypeId);
|
||||
}
|
||||
|
||||
// Apply location and category filters if provided
|
||||
final initialFilters = <String, List<String>>{};
|
||||
if (widget.initialLocation != null) {
|
||||
initialFilters['state'] = [widget.initialLocation!];
|
||||
}
|
||||
if (widget.initialCategory != null) {
|
||||
initialFilters['specialization'] = [widget.initialCategory!];
|
||||
}
|
||||
if (initialFilters.isNotEmpty) {
|
||||
notifier.applyFilters(initialFilters);
|
||||
}
|
||||
|
||||
// Trigger initial search if query provided
|
||||
if (widget.initialQuery != null && widget.initialQuery!.isNotEmpty) {
|
||||
notifier.search(widget.initialQuery!);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -397,6 +423,7 @@ class _AgentCardState extends State<_AgentCard> {
|
||||
imageUrl: agent.avatarUrl,
|
||||
width: double.infinity,
|
||||
height: 265,
|
||||
alignment: Alignment.topCenter,
|
||||
errorWidget: (_) => Container(
|
||||
width: double.infinity,
|
||||
height: 265,
|
||||
|
||||
Reference in New Issue
Block a user