Services
Overview of service classes in the mobile app.
ProviderService
Handles provider-related operations.
Location: lib/services/provider_service.dart
Key Methods:
getProviderProfile(providerId)- Get provider detailsupdateOnlineStatus(userId, isOnline)- Update availabilitygetAvailableJobs(userId)- Get available job listingsacceptJob(jobId, userId)- Accept a job requeststartJob(jobId, userId)- Mark job as in progresscompleteJob(jobId, userId)- Complete a jobcreateReview(...)- Submit a review
ServiceSeekerService
Handles service seeker operations.
Location: lib/services/service_seeker_service.dart
Key Methods:
createJob(...)- Create a new job requestgetUserJobs(userId)- Get user's job historycancelJob(jobId)- Cancel a jobhasCompleteProfile(userData)- Check profile completeness
ChatService
Handles messaging and conversations.
Location: lib/services/chat_service.dart
Key Methods:
getConversations(userId)- Get user conversationsgetMessages(conversationId)- Get conversation messagessendMessage(...)- Send a messagestartConversation(...)- Start new conversation
LocationService
Handles location tracking and geolocation.
Location: lib/services/location_service.dart
Features:
- Get current location
- Track location updates
- Upload location to backend
Usage Example
// In a widget or provider
final jobs = await ProviderService.getAvailableJobs(userId: userId);
// Handle response
if (jobs != null && jobs.isNotEmpty) {
setState(() {
_availableJobs = jobs;
});
}
Error Handling
All services should handle errors:
try {
final result = await ProviderService.acceptJob(
jobId: jobId,
userId: userId,
);
if (result != null) {
// Success
}
} catch (e) {
// Handle error
print('Error: $e');
}
Best Practices
- Centralize API calls in service classes
- Handle errors consistently
- Return nullable types to indicate failure
- Use async/await for asynchronous operations
- Validate responses before using data