UserService constructor

UserService({
  1. required SharedPreferences prefs,
  2. required Uuid uuid,
})

Creates a new user service with required dependencies.

Both prefs and uuid are required dependencies that enable the service to store data persistently and generate unique identifiers.

Dependency Injection

This constructor supports dependency injection for better testability:

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

// Testing usage
final mockPrefs = MockSharedPreferences();
final mockUuid = MockUuid();
final userService = UserService(prefs: mockPrefs, uuid: mockUuid);

prefs The SharedPreferences instance for data persistence. uuid The UUID generator for creating unique identifiers.

Implementation

UserService({required SharedPreferences prefs, required Uuid uuid})
    : _prefs = prefs,
      _uuid = uuid;