forked from eatvio/eatvio_app
feat(profile): delete photo
This commit is contained in:
@@ -92,4 +92,9 @@ class ProfileCubit extends Cubit<ProfileState> {
|
||||
await profileRepository.uploadPhoto(await ImageCompressUtility.compressFile(file));
|
||||
return await getMyProfile();
|
||||
}
|
||||
|
||||
deletePhoto() async {
|
||||
await profileRepository.deletePhoto();
|
||||
return await getMyProfile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,7 +737,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
child: Row(
|
||||
children: [
|
||||
PopupMenuButton(
|
||||
onSelected: (value) {
|
||||
onSelected: (value) async {
|
||||
if (value == 'view') {
|
||||
context.pushTransparentRoute(
|
||||
rootNavigator: true,
|
||||
@@ -797,6 +797,10 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
if (value == 'delete') {
|
||||
await profileCubit.deletePhoto();
|
||||
await sl<ProfileAvatarCubit>().getMyProfile();
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
|
||||
@@ -163,4 +163,12 @@ class ProfileRepository {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deletePhoto() async {
|
||||
try {
|
||||
return await profileService.deletePhoto();
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,4 +96,7 @@ abstract class ProfileService {
|
||||
Future<void> uploadPhoto({
|
||||
@Part(name: 'photo') required File photo,
|
||||
});
|
||||
|
||||
@DELETE('/api/profile/photo/delete')
|
||||
Future<void> deletePhoto();
|
||||
}
|
||||
|
||||
@@ -571,6 +571,31 @@ class _ProfileService implements ProfileService {
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deletePhoto() async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<void>(Options(
|
||||
method: 'DELETE',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/profile/photo/delete',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
||||
if (T != dynamic &&
|
||||
!(requestOptions.responseType == ResponseType.bytes ||
|
||||
|
||||
Reference in New Issue
Block a user