import 'dart:io'; import 'package:dio/dio.dart'; import '../../../../core/network/i_api_client.dart'; import '../../../../data/models/user_profile.dart'; class UserProfileService { static const _prefix = '/api/v1/users'; final IApiClient _client; UserProfileService(this._client); Future getMe() async { final response = await _client.get>('$_prefix/me'); final data = response.data; if (data == null) { throw StateError('Invalid getMe response: empty payload'); } return UserProfile.fromJson(data); } Future updateMe(UserUpdateRequest request) async { final response = await _client.patch>( '$_prefix/me', data: request.toJson(), ); final data = response.data; if (data == null) { throw StateError('Invalid updateMe response: empty payload'); } return UserProfile.fromJson(data); } Future uploadAvatar(File file) async { final formData = FormData.fromMap({ 'file': await MultipartFile.fromFile( file.path, filename: file.path.split('/').last, ), }); final response = await _client.post>( '$_prefix/me/avatar', data: formData, ); final data = response.data; if (data == null || data['url'] is! String) { throw StateError('Invalid uploadAvatar response: missing url'); } return data['url'] as String; } }