feat: Implement agent network management and refactor app navigation with a new AppShell component.
This commit is contained in:
@@ -195,6 +195,33 @@ class AgentsRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get received connection requests: GET /connection-requests/received?status=...
|
||||
Future<List<Map<String, dynamic>>> getReceivedRequests(String status) async {
|
||||
try {
|
||||
final response = await _dio.get(
|
||||
'${ApiConstants.connectionRequests}/received',
|
||||
queryParameters: {'status': status},
|
||||
);
|
||||
final data = response.data['data'] as List<dynamic>? ?? [];
|
||||
return data.cast<Map<String, dynamic>>();
|
||||
} on DioException catch (_) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// Respond to connection request: PATCH /connection-requests/{id}/respond
|
||||
Future<bool> respondToRequest(String requestId, String status) async {
|
||||
try {
|
||||
await _dio.patch(
|
||||
'${ApiConstants.connectionRequests}/$requestId/respond',
|
||||
data: {'status': status},
|
||||
);
|
||||
return true;
|
||||
} on DioException catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// Get agent types: GET /agent-types
|
||||
/// Response: { success, data: [...] }
|
||||
Future<List<AgentType>> getAgentTypes() async {
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:real_estate_mobile/features/agents/data/agents_repository.dart';
|
||||
|
||||
class AgentNetworkState {
|
||||
final List<Map<String, dynamic>> pendingRequests;
|
||||
final List<Map<String, dynamic>> connections;
|
||||
final bool isLoading;
|
||||
final String? error;
|
||||
final Set<String> processingIds;
|
||||
|
||||
const AgentNetworkState({
|
||||
this.pendingRequests = const [],
|
||||
this.connections = const [],
|
||||
this.isLoading = true,
|
||||
this.error,
|
||||
this.processingIds = const {},
|
||||
});
|
||||
|
||||
AgentNetworkState copyWith({
|
||||
List<Map<String, dynamic>>? pendingRequests,
|
||||
List<Map<String, dynamic>>? connections,
|
||||
bool? isLoading,
|
||||
String? error,
|
||||
Set<String>? processingIds,
|
||||
bool clearError = false,
|
||||
}) {
|
||||
return AgentNetworkState(
|
||||
pendingRequests: pendingRequests ?? this.pendingRequests,
|
||||
connections: connections ?? this.connections,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
error: clearError ? null : (error ?? this.error),
|
||||
processingIds: processingIds ?? this.processingIds,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AgentNetworkNotifier extends StateNotifier<AgentNetworkState> {
|
||||
final AgentsRepository _repo;
|
||||
|
||||
AgentNetworkNotifier(this._repo) : super(const AgentNetworkState()) {
|
||||
loadData();
|
||||
}
|
||||
|
||||
Future<void> loadData() async {
|
||||
state = state.copyWith(isLoading: true, clearError: true);
|
||||
try {
|
||||
final results = await Future.wait([
|
||||
_repo.getReceivedRequests('PENDING'),
|
||||
_repo.getReceivedRequests('ACCEPTED'),
|
||||
]);
|
||||
state = state.copyWith(
|
||||
pendingRequests: results[0],
|
||||
connections: results[1],
|
||||
isLoading: false,
|
||||
);
|
||||
} catch (e) {
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
error: 'Failed to load network data',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> acceptRequest(String requestId) async {
|
||||
if (state.processingIds.contains(requestId)) return;
|
||||
state = state.copyWith(
|
||||
processingIds: {...state.processingIds, requestId},
|
||||
);
|
||||
|
||||
final success = await _repo.respondToRequest(requestId, 'ACCEPTED');
|
||||
if (success) {
|
||||
// Move from pending to connections
|
||||
final request = state.pendingRequests.firstWhere(
|
||||
(r) => r['id'] == requestId,
|
||||
orElse: () => <String, dynamic>{},
|
||||
);
|
||||
state = state.copyWith(
|
||||
pendingRequests:
|
||||
state.pendingRequests.where((r) => r['id'] != requestId).toList(),
|
||||
connections: request.isNotEmpty
|
||||
? [request, ...state.connections]
|
||||
: state.connections,
|
||||
processingIds: state.processingIds
|
||||
.where((id) => id != requestId)
|
||||
.toSet(),
|
||||
);
|
||||
} else {
|
||||
state = state.copyWith(
|
||||
processingIds: state.processingIds
|
||||
.where((id) => id != requestId)
|
||||
.toSet(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> rejectRequest(String requestId) async {
|
||||
if (state.processingIds.contains(requestId)) return;
|
||||
state = state.copyWith(
|
||||
processingIds: {...state.processingIds, requestId},
|
||||
);
|
||||
|
||||
final success = await _repo.respondToRequest(requestId, 'REJECTED');
|
||||
if (success) {
|
||||
state = state.copyWith(
|
||||
pendingRequests:
|
||||
state.pendingRequests.where((r) => r['id'] != requestId).toList(),
|
||||
processingIds: state.processingIds
|
||||
.where((id) => id != requestId)
|
||||
.toSet(),
|
||||
);
|
||||
} else {
|
||||
state = state.copyWith(
|
||||
processingIds: state.processingIds
|
||||
.where((id) => id != requestId)
|
||||
.toSet(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final agentNetworkProvider =
|
||||
StateNotifierProvider.autoDispose<AgentNetworkNotifier, AgentNetworkState>(
|
||||
(ref) => AgentNetworkNotifier(AgentsRepository()),
|
||||
);
|
||||
@@ -1,13 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:go_router/go_router.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/agent_detail_provider.dart';
|
||||
import 'package:real_estate_mobile/features/auth/presentation/providers/auth_provider.dart';
|
||||
import 'package:real_estate_mobile/features/home/presentation/widgets/home_header.dart';
|
||||
|
||||
class AgentDetailScreen extends ConsumerStatefulWidget {
|
||||
final String agentId;
|
||||
@@ -41,16 +39,14 @@ class _AgentDetailScreenState extends ConsumerState<AgentDetailScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
final state = ref.watch(agentDetailProvider(widget.agentId));
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: state.isLoading
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.accentOrange))
|
||||
: state.error != null
|
||||
? _buildError(state.error!)
|
||||
: _buildContent(state),
|
||||
bottomNavigationBar: _buildBottomNavBar(),
|
||||
);
|
||||
if (state.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.accentOrange));
|
||||
}
|
||||
if (state.error != null) {
|
||||
return _buildError(state.error!);
|
||||
}
|
||||
return _buildContent(state);
|
||||
}
|
||||
|
||||
Widget _buildError(String error) {
|
||||
@@ -86,8 +82,6 @@ class _AgentDetailScreenState extends ConsumerState<AgentDetailScreen> {
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
SafeArea(bottom: false, child: const HomeHeader()),
|
||||
|
||||
// ── Avatar Section ──
|
||||
const SizedBox(height: 16),
|
||||
_buildAvatarSection(agent),
|
||||
@@ -1033,90 +1027,6 @@ class _AgentDetailScreenState extends ConsumerState<AgentDetailScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// ── Bottom Nav ──
|
||||
Widget _buildBottomNavBar() {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
border: Border(top: BorderSide(color: Color(0xFFE8E8E8), width: 1)),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_buildNavItem(
|
||||
svgPath: 'assets/icons/nav_home_icon.svg',
|
||||
fallbackIcon: Icons.home,
|
||||
onTap: () => context.go('/home'),
|
||||
),
|
||||
_buildNavItem(
|
||||
svgPath: 'assets/icons/nav_list_icon.svg',
|
||||
fallbackIcon: Icons.list,
|
||||
isSelected: true,
|
||||
onTap: () => context.go('/agents/search'),
|
||||
),
|
||||
_buildNavItem(
|
||||
svgPath: 'assets/icons/nav_messages_icon.svg',
|
||||
fallbackIcon: Icons.chat_bubble,
|
||||
onTap: () {
|
||||
if (ref.read(authProvider).status !=
|
||||
AuthStatus.authenticated) {
|
||||
context.push('/login');
|
||||
return;
|
||||
}
|
||||
context.go('/messages');
|
||||
},
|
||||
),
|
||||
_buildNavItem(
|
||||
svgPath: 'assets/icons/nav_profile_icon.svg',
|
||||
fallbackIcon: Icons.person_outline,
|
||||
onTap: () {
|
||||
if (ref.read(authProvider).status !=
|
||||
AuthStatus.authenticated) {
|
||||
context.push('/login');
|
||||
return;
|
||||
}
|
||||
context.push('/profile');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavItem({
|
||||
required String svgPath,
|
||||
required IconData fallbackIcon,
|
||||
bool isSelected = false,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: SvgPicture.asset(
|
||||
svgPath,
|
||||
width: 24,
|
||||
height: 24,
|
||||
colorFilter: ColorFilter.mode(
|
||||
isSelected ? AppColors.primaryDark : AppColors.accentOrange,
|
||||
BlendMode.srcIn,
|
||||
),
|
||||
placeholderBuilder: (_) => Icon(
|
||||
fallbackIcon,
|
||||
size: 24,
|
||||
color: isSelected ? AppColors.primaryDark : AppColors.accentOrange,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Expandable Chips Section ──
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:go_router/go_router.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/agent_detail_provider.dart';
|
||||
import 'package:real_estate_mobile/features/auth/presentation/providers/auth_provider.dart';
|
||||
import 'package:real_estate_mobile/features/home/presentation/widgets/home_header.dart';
|
||||
import 'package:real_estate_mobile/features/profile/data/profile_repository.dart';
|
||||
|
||||
/// Provider that fetches the agent's own profile ID from /agents/profile/me
|
||||
@@ -30,51 +27,42 @@ class AgentHomeScreen extends ConsumerWidget {
|
||||
final myProfileAsync = ref.watch(_agentMyProfileProvider);
|
||||
|
||||
return myProfileAsync.when(
|
||||
loading: () => const Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AppColors.accentOrange,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
loading: () => const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: AppColors.accentOrange,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
error: (_, __) => Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.error_outline,
|
||||
size: 48, color: AppColors.accentOrange),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Failed to load profile',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primaryDark)),
|
||||
const SizedBox(height: 12),
|
||||
TextButton(
|
||||
onPressed: () => ref.invalidate(_agentMyProfileProvider),
|
||||
child: const Text('Retry',
|
||||
style: TextStyle(color: AppColors.accentOrange)),
|
||||
),
|
||||
],
|
||||
),
|
||||
error: (_, __) => Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.error_outline,
|
||||
size: 48, color: AppColors.accentOrange),
|
||||
const SizedBox(height: 16),
|
||||
const Text('Failed to load profile',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primaryDark)),
|
||||
const SizedBox(height: 12),
|
||||
TextButton(
|
||||
onPressed: () => ref.invalidate(_agentMyProfileProvider),
|
||||
child: const Text('Retry',
|
||||
style: TextStyle(color: AppColors.accentOrange)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
data: (agentProfileId) {
|
||||
if (agentProfileId == null) {
|
||||
return const Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: Center(
|
||||
child: Text('No agent profile found',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 16,
|
||||
color: AppColors.primaryDark)),
|
||||
),
|
||||
return const Center(
|
||||
child: Text('No agent profile found',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 16,
|
||||
color: AppColors.primaryDark)),
|
||||
);
|
||||
}
|
||||
return _AgentHomeContent(agentProfileId: agentProfileId);
|
||||
@@ -97,16 +85,14 @@ class _AgentHomeContentState extends ConsumerState<_AgentHomeContent> {
|
||||
Widget build(BuildContext context) {
|
||||
final state = ref.watch(agentDetailProvider(widget.agentProfileId));
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: state.isLoading
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.accentOrange))
|
||||
: state.error != null
|
||||
? _buildError(state.error!)
|
||||
: _buildContent(state),
|
||||
bottomNavigationBar: _buildBottomNavBar(),
|
||||
);
|
||||
if (state.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.accentOrange));
|
||||
}
|
||||
if (state.error != null) {
|
||||
return _buildError(state.error!);
|
||||
}
|
||||
return _buildContent(state);
|
||||
}
|
||||
|
||||
Widget _buildError(String error) {
|
||||
@@ -140,8 +126,6 @@ class _AgentHomeContentState extends ConsumerState<_AgentHomeContent> {
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
SafeArea(bottom: false, child: const HomeHeader()),
|
||||
const SizedBox(height: 12),
|
||||
_buildCoverAndAvatar(agent),
|
||||
const SizedBox(height: 16),
|
||||
_buildStatusSection(agent),
|
||||
@@ -968,97 +952,6 @@ class _AgentHomeContentState extends ConsumerState<_AgentHomeContent> {
|
||||
);
|
||||
}
|
||||
|
||||
// ── Bottom Navigation Bar ──
|
||||
Widget _buildBottomNavBar() {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
border: Border(
|
||||
top: BorderSide(color: Color(0xFFE8E8E8), width: 1),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_buildNavItem(
|
||||
svgPath: 'assets/icons/nav_home_icon.svg',
|
||||
fallbackIcon: Icons.home,
|
||||
isSelected: true,
|
||||
onTap: () {},
|
||||
),
|
||||
_buildNavItem(
|
||||
svgPath: 'assets/icons/nav_list_icon.svg',
|
||||
fallbackIcon: Icons.list,
|
||||
isSelected: false,
|
||||
onTap: () => context.push('/agents/search'),
|
||||
),
|
||||
_buildNavItem(
|
||||
svgPath: 'assets/icons/nav_messages_icon.svg',
|
||||
fallbackIcon: Icons.chat_bubble,
|
||||
isSelected: false,
|
||||
onTap: () {
|
||||
final authState = ref.read(authProvider);
|
||||
if (authState.status != AuthStatus.authenticated) {
|
||||
context.push('/login');
|
||||
return;
|
||||
}
|
||||
context.push('/messages');
|
||||
},
|
||||
),
|
||||
_buildNavItem(
|
||||
svgPath: 'assets/icons/nav_profile_icon.svg',
|
||||
fallbackIcon: Icons.person_outline,
|
||||
isSelected: false,
|
||||
onTap: () {
|
||||
final authState = ref.read(authProvider);
|
||||
if (authState.status != AuthStatus.authenticated) {
|
||||
context.push('/login');
|
||||
return;
|
||||
}
|
||||
context.push('/profile');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavItem({
|
||||
required String svgPath,
|
||||
required IconData fallbackIcon,
|
||||
required bool isSelected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: SvgPicture.asset(
|
||||
svgPath,
|
||||
width: 24,
|
||||
height: 24,
|
||||
colorFilter: isSelected
|
||||
? const ColorFilter.mode(
|
||||
AppColors.primaryDark, BlendMode.srcIn)
|
||||
: const ColorFilter.mode(
|
||||
AppColors.accentOrange, BlendMode.srcIn),
|
||||
placeholderBuilder: (_) => Icon(
|
||||
fallbackIcon,
|
||||
size: 24,
|
||||
color:
|
||||
isSelected ? AppColors.primaryDark : AppColors.accentOrange,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Testimonial Card (same as agent detail screen) ──
|
||||
|
||||
@@ -0,0 +1,521 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.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/presentation/providers/agent_network_provider.dart';
|
||||
|
||||
class AgentNetworkScreen extends ConsumerWidget {
|
||||
const AgentNetworkScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final state = ref.watch(agentNetworkProvider);
|
||||
|
||||
if (state.isLoading) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.accentOrange));
|
||||
}
|
||||
if (state.error != null) {
|
||||
return _buildError(context, ref, state.error!);
|
||||
}
|
||||
return _buildContent(context, ref, state);
|
||||
}
|
||||
|
||||
Widget _buildError(BuildContext context, WidgetRef ref, String error) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.error_outline,
|
||||
size: 48, color: AppColors.accentOrange),
|
||||
const SizedBox(height: 16),
|
||||
Text(error,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primaryDark,
|
||||
)),
|
||||
const SizedBox(height: 12),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
ref.read(agentNetworkProvider.notifier).loadData(),
|
||||
child: const Text('Try Again',
|
||||
style: TextStyle(color: AppColors.accentOrange)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContent(
|
||||
BuildContext context, WidgetRef ref, AgentNetworkState state) {
|
||||
return RefreshIndicator(
|
||||
color: AppColors.accentOrange,
|
||||
onRefresh: () => ref.read(agentNetworkProvider.notifier).loadData(),
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// ── Pending Requests Section ──
|
||||
if (state.pendingRequests.isNotEmpty) ...[
|
||||
_buildSectionHeader('Pending Requests',
|
||||
count: state.pendingRequests.length),
|
||||
const SizedBox(height: 12),
|
||||
...state.pendingRequests.map((request) => _RequestCard(
|
||||
data: request,
|
||||
isProcessing:
|
||||
state.processingIds.contains(request['id']),
|
||||
)),
|
||||
const SizedBox(height: 16),
|
||||
Divider(
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.1),
|
||||
height: 1),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
|
||||
// ── Manage My Network Section ──
|
||||
_buildManageNetworkHeader(context),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
if (state.connections.isEmpty)
|
||||
_buildEmptyState(
|
||||
icon: Icons.people_outline,
|
||||
message: 'No connections yet',
|
||||
subtitle:
|
||||
'When you accept connection requests, they will appear here.',
|
||||
)
|
||||
else
|
||||
...state.connections
|
||||
.map((conn) => _ConnectionCard(data: conn)),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(String title, {int? count}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
),
|
||||
if (count != null && count > 0) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.accentOrange,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'$count',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildManageNetworkHeader(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 0),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.1),
|
||||
width: 0.5),
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text(
|
||||
'Manage My Network',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Icon(Icons.arrow_forward,
|
||||
size: 20,
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.7)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState({
|
||||
required IconData icon,
|
||||
required String message,
|
||||
String? subtitle,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 40),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 48, color: AppColors.primaryDark.withValues(alpha: 0.3)),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
message,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
),
|
||||
if (subtitle != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
subtitle,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 14,
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ── Relative time formatting (same as web) ──
|
||||
String _formatRelativeTime(String? dateStr) {
|
||||
if (dateStr == null || dateStr.isEmpty) return '';
|
||||
try {
|
||||
final date = DateTime.parse(dateStr);
|
||||
final now = DateTime.now();
|
||||
final diff = now.difference(date);
|
||||
|
||||
if (diff.inSeconds < 60) return 'Just now';
|
||||
if (diff.inMinutes < 60) return '${diff.inMinutes}m ago';
|
||||
if (diff.inHours < 24) return '${diff.inHours}h ago';
|
||||
if (diff.inDays < 7) return '${diff.inDays}d ago';
|
||||
return DateFormat('MMM d').format(date);
|
||||
} catch (_) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// ── Date formatting for connections ──
|
||||
String _formatConnectedDate(String? dateStr) {
|
||||
if (dateStr == null || dateStr.isEmpty) return '';
|
||||
try {
|
||||
final date = DateTime.parse(dateStr);
|
||||
return 'Connected on ${DateFormat('MMM d, y').format(date)}';
|
||||
} catch (_) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// ── Request Card (pending connection requests with accept/reject) ──
|
||||
class _RequestCard extends ConsumerWidget {
|
||||
final Map<String, dynamic> data;
|
||||
final bool isProcessing;
|
||||
|
||||
const _RequestCard({required this.data, required this.isProcessing});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final user = data['user'] as Map<String, dynamic>? ?? {};
|
||||
final userName =
|
||||
user['email'] as String? ?? user['name'] as String? ?? 'User';
|
||||
final avatar = user['avatar'] as String?;
|
||||
final message = data['message'] as String?;
|
||||
final requestId = data['id'] as String;
|
||||
final createdAt = data['createdAt'] as String?;
|
||||
final relativeTime = _formatRelativeTime(createdAt);
|
||||
|
||||
return Opacity(
|
||||
opacity: isProcessing ? 0.5 : 1.0,
|
||||
child: AbsorbPointer(
|
||||
absorbing: isProcessing,
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
// Avatar
|
||||
ClipOval(
|
||||
child: SizedBox(
|
||||
width: 56,
|
||||
height: 56,
|
||||
child: avatar != null && avatar.isNotEmpty
|
||||
? S3Image(
|
||||
imageUrl: avatar,
|
||||
width: 56,
|
||||
height: 56,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Container(
|
||||
color: const Color(0xFFE0E0E0),
|
||||
child: const Icon(Icons.person,
|
||||
size: 28, color: AppColors.primaryDark),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Name + message + time
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
userName,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(Icons.verified_user_outlined,
|
||||
size: 16,
|
||||
color: AppColors.primaryDark
|
||||
.withValues(alpha: 0.5)),
|
||||
],
|
||||
),
|
||||
if (message != null && message.isNotEmpty)
|
||||
Text(
|
||||
message,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 14,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.link,
|
||||
size: 14,
|
||||
color: AppColors.primaryDark
|
||||
.withValues(alpha: 0.5)),
|
||||
const SizedBox(width: 4),
|
||||
const Text(
|
||||
'Mutual Connection',
|
||||
style: TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w200,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
),
|
||||
if (relativeTime.isNotEmpty) ...[
|
||||
const Spacer(),
|
||||
Text(
|
||||
relativeTime,
|
||||
style: TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 12,
|
||||
color: AppColors.primaryDark
|
||||
.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// Reject button (X)
|
||||
GestureDetector(
|
||||
onTap: () => ref
|
||||
.read(agentNetworkProvider.notifier)
|
||||
.rejectRequest(requestId),
|
||||
child: Container(
|
||||
width: 33,
|
||||
height: 31,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color:
|
||||
AppColors.primaryDark.withValues(alpha: 0.3),
|
||||
width: 1),
|
||||
),
|
||||
child: Icon(Icons.close,
|
||||
size: 18,
|
||||
color:
|
||||
AppColors.primaryDark.withValues(alpha: 0.6)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
// Accept button (checkmark)
|
||||
GestureDetector(
|
||||
onTap: () => ref
|
||||
.read(agentNetworkProvider.notifier)
|
||||
.acceptRequest(requestId),
|
||||
child: Container(
|
||||
width: 33,
|
||||
height: 31,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.accentOrange,
|
||||
),
|
||||
child: const Icon(Icons.check,
|
||||
size: 20, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Connection Card (accepted connections in Manage My Network) ──
|
||||
class _ConnectionCard extends StatelessWidget {
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
const _ConnectionCard({required this.data});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = data['user'] as Map<String, dynamic>? ?? {};
|
||||
final userName =
|
||||
user['email'] as String? ?? user['name'] as String? ?? 'User';
|
||||
final userEmail = user['email'] as String? ?? '';
|
||||
final avatar = user['avatar'] as String?;
|
||||
final respondedAt = data['respondedAt'] as String?;
|
||||
final connectedDate = _formatConnectedDate(respondedAt);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
// Avatar
|
||||
ClipOval(
|
||||
child: SizedBox(
|
||||
width: 56,
|
||||
height: 56,
|
||||
child: avatar != null && avatar.isNotEmpty
|
||||
? S3Image(
|
||||
imageUrl: avatar,
|
||||
width: 56,
|
||||
height: 56,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Container(
|
||||
color: const Color(0xFFE0E0E0),
|
||||
child: const Icon(Icons.person,
|
||||
size: 28, color: AppColors.primaryDark),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Name + email + connected date
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
userName,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(Icons.verified_user_outlined,
|
||||
size: 16,
|
||||
color: AppColors.primaryDark
|
||||
.withValues(alpha: 0.5)),
|
||||
],
|
||||
),
|
||||
if (userEmail.isNotEmpty)
|
||||
Text(
|
||||
userEmail,
|
||||
style: TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 13,
|
||||
color:
|
||||
AppColors.primaryDark.withValues(alpha: 0.6),
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (connectedDate.isNotEmpty)
|
||||
Text(
|
||||
connectedDate,
|
||||
style: TextStyle(
|
||||
fontFamily: 'SourceSerif4',
|
||||
fontSize: 12,
|
||||
color:
|
||||
AppColors.primaryDark.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// Message button
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
// Navigate to messages — if we have userId, could create/open conversation
|
||||
context.push('/messages');
|
||||
},
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.accentOrange.withValues(alpha: 0.1),
|
||||
),
|
||||
child: const Icon(Icons.chat_bubble_outline,
|
||||
size: 18, color: AppColors.accentOrange),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,6 @@ import 'package:real_estate_mobile/features/agents/data/models/agent_profile.dar
|
||||
import 'package:real_estate_mobile/features/agents/data/models/agent_type.dart';
|
||||
import 'package:real_estate_mobile/features/agents/presentation/providers/search_agents_provider.dart';
|
||||
import 'package:real_estate_mobile/features/agents/presentation/widgets/agent_filter_sheet.dart';
|
||||
import 'package:real_estate_mobile/features/auth/presentation/providers/auth_provider.dart';
|
||||
import 'package:real_estate_mobile/features/home/presentation/widgets/home_header.dart';
|
||||
|
||||
class AgentSearchScreen extends ConsumerStatefulWidget {
|
||||
final String? initialQuery;
|
||||
@@ -79,23 +77,14 @@ class _AgentSearchScreenState extends ConsumerState<AgentSearchScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
final state = ref.watch(searchAgentsProvider);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: Column(
|
||||
children: [
|
||||
// Shared header
|
||||
SafeArea(
|
||||
bottom: false,
|
||||
child: const HomeHeader(),
|
||||
),
|
||||
_buildSearchBar(),
|
||||
const SizedBox(height: 12),
|
||||
_buildFilterChips(state.agentTypes, state.selectedAgentTypeId),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(child: _buildAgentList(state)),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: _buildBottomNavBar(),
|
||||
return Column(
|
||||
children: [
|
||||
_buildSearchBar(),
|
||||
const SizedBox(height: 12),
|
||||
_buildFilterChips(state.agentTypes, state.selectedAgentTypeId),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(child: _buildAgentList(state)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -359,99 +348,6 @@ class _AgentSearchScreenState extends ConsumerState<AgentSearchScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// ── Bottom Navigation Bar (shared style matching HomeScreen) ──
|
||||
Widget _buildBottomNavBar() {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
border: Border(
|
||||
top: BorderSide(color: Color(0xFFE8E8E8), width: 1),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_buildNavItem(
|
||||
index: 0,
|
||||
svgPath: 'assets/icons/nav_home_icon.svg',
|
||||
fallbackIcon: Icons.home,
|
||||
isSelected: false,
|
||||
onTap: () => context.go('/home'),
|
||||
),
|
||||
_buildNavItem(
|
||||
index: 1,
|
||||
svgPath: 'assets/icons/nav_list_icon.svg',
|
||||
fallbackIcon: Icons.list,
|
||||
isSelected: true,
|
||||
onTap: () {},
|
||||
),
|
||||
_buildNavItem(
|
||||
index: 2,
|
||||
svgPath: 'assets/icons/nav_messages_icon.svg',
|
||||
fallbackIcon: Icons.chat_bubble,
|
||||
isSelected: false,
|
||||
onTap: () {
|
||||
final authState = ref.read(authProvider);
|
||||
if (authState.status != AuthStatus.authenticated) {
|
||||
context.push('/login');
|
||||
return;
|
||||
}
|
||||
context.go('/messages');
|
||||
},
|
||||
),
|
||||
_buildNavItem(
|
||||
index: 3,
|
||||
svgPath: 'assets/icons/nav_profile_icon.svg',
|
||||
fallbackIcon: Icons.person_outline,
|
||||
isSelected: false,
|
||||
onTap: () {
|
||||
final authState = ref.read(authProvider);
|
||||
if (authState.status != AuthStatus.authenticated) {
|
||||
context.push('/login');
|
||||
return;
|
||||
}
|
||||
context.push('/profile');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavItem({
|
||||
required int index,
|
||||
required String svgPath,
|
||||
required IconData fallbackIcon,
|
||||
required bool isSelected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: SvgPicture.asset(
|
||||
svgPath,
|
||||
width: 24,
|
||||
height: 24,
|
||||
colorFilter: isSelected
|
||||
? const ColorFilter.mode(AppColors.primaryDark, BlendMode.srcIn)
|
||||
: const ColorFilter.mode(AppColors.accentOrange, BlendMode.srcIn),
|
||||
placeholderBuilder: (_) => Icon(
|
||||
fallbackIcon,
|
||||
size: 24,
|
||||
color: isSelected ? AppColors.primaryDark : AppColors.accentOrange,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Agent Card Widget matching Figma design ---
|
||||
|
||||
Reference in New Issue
Block a user