getUser method

Future<UserModel?> getUser()

Retrieves the current user's profile information.

Returns a UserModel representing the user's data.

Implementation

Future<UserModel?> getUser() async {
  if (!loggedIn || accessToken == null) {
    throw Exception('User is not logged in or access token is missing.');
  }

  try {
    // Make an API request to get user data
    final response = await _dio.get('https://api.spotify.com/v1/me');

    // Parse the response into a UserModel
    return UserModel.fromMap(
      response.data,
    );
  } catch (e) {
    throw Exception('Error fetching user data: $e');
  }
}