UserService class

Service for managing user-specific data and preferences.

This service handles user identification and persistent storage of user-specific settings using SharedPreferences. It ensures each device has a unique, persistent user identifier for tracking observations and user preferences across app sessions.

User Identification Strategy

The service uses a device-based identification approach:

  • Anonymous: No personal information is collected or stored
  • Persistent: User ID persists across app restarts and updates
  • Unique: Each device gets a unique UUID v4 identifier
  • Privacy-Focused: No tracking across devices or accounts

Data Storage

User data is stored locally using SharedPreferences:

  • Location: Platform-specific secure storage
  • Persistence: Survives app updates and device restarts
  • Security: Uses platform's secure storage mechanisms
  • Backup: May be included in device backups (platform-dependent)

Usage Example

final prefs = await SharedPreferences.getInstance();
final uuid = Uuid();
final userService = UserService(prefs: prefs, uuid: uuid);

// Get user ID (creates one if it doesn't exist)
final userId = await userService.getUserId();
print('User ID: $userId');

// Use in observations
final observation = Observation(
  id: 'obs_123',
  userId: userId,
  // ... other fields
);

Privacy Considerations

  • User IDs are generated locally and never transmitted to identify individuals
  • IDs are used only for data organization and quality assessment
  • No personal information is associated with user IDs
  • Users can reset their ID by clearing app data

Integration Points

The service integrates with:

  • Observation model for tracking observation sources
  • Analytics systems for usage patterns (anonymized)
  • Data quality systems for contribution assessment

See also:

Constructors

UserService({required SharedPreferences prefs, required Uuid uuid})
Creates a new user service with required dependencies.

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

clearUserId() Future<bool>
Clears the stored user ID, effectively resetting the user identity.
getUserId() Future<String>
Gets the unique user ID for this device.
hasUserId() Future<bool>
Checks if a user ID has been generated for this device.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited