Skip to main content

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 details
  • updateOnlineStatus(userId, isOnline) - Update availability
  • getAvailableJobs(userId) - Get available job listings
  • acceptJob(jobId, userId) - Accept a job request
  • startJob(jobId, userId) - Mark job as in progress
  • completeJob(jobId, userId) - Complete a job
  • createReview(...) - Submit a review

ServiceSeekerService

Handles service seeker operations.

Location: lib/services/service_seeker_service.dart

Key Methods:

  • createJob(...) - Create a new job request
  • getUserJobs(userId) - Get user's job history
  • cancelJob(jobId) - Cancel a job
  • hasCompleteProfile(userData) - Check profile completeness

ChatService

Handles messaging and conversations.

Location: lib/services/chat_service.dart

Key Methods:

  • getConversations(userId) - Get user conversations
  • getMessages(conversationId) - Get conversation messages
  • sendMessage(...) - Send a message
  • startConversation(...) - 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

  1. Centralize API calls in service classes
  2. Handle errors consistently
  3. Return nullable types to indicate failure
  4. Use async/await for asynchronous operations
  5. Validate responses before using data