feat: Implement pull-to-refresh functionality on the agent detail screen by adding a refresh method to the provider and integrating a RefreshIndicator.
This commit is contained in:
@@ -399,6 +399,24 @@ class AgentDetailNotifier extends StateNotifier<AgentDetailState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> refresh() async {
|
||||
try {
|
||||
final results = await Future.wait([
|
||||
_repo.getAgentById(agentId),
|
||||
_repo.getFieldValues(agentId),
|
||||
_repo.getTestimonials(agentId),
|
||||
]);
|
||||
state = state.copyWith(
|
||||
agent: results[0] as AgentProfile,
|
||||
fieldValues: results[1] as List<AgentFieldValue>,
|
||||
testimonials: results[2] as List<Map<String, dynamic>>,
|
||||
isLoading: false,
|
||||
);
|
||||
// Also refresh connection status
|
||||
await loadConnectionStatus();
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> loadConnectionStatus() async {
|
||||
final status = await _repo.getConnectionStatus(agentId);
|
||||
state = state.copyWith(connectionStatus: status);
|
||||
|
||||
@@ -92,8 +92,14 @@ class _AgentDetailScreenState extends ConsumerState<AgentDetailScreen> {
|
||||
|
||||
Widget _buildContent(AgentDetailState state) {
|
||||
final agent = state.agent!;
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
return RefreshIndicator(
|
||||
color: AppColors.accentOrange,
|
||||
onRefresh: () => ref
|
||||
.read(agentDetailProvider(widget.agentId).notifier)
|
||||
.refresh(),
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Column(
|
||||
children: [
|
||||
// ── Avatar Section ──
|
||||
const SizedBox(height: 16),
|
||||
@@ -132,6 +138,7 @@ class _AgentDetailScreenState extends ConsumerState<AgentDetailScreen> {
|
||||
const SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user