49 lines
1.3 KiB
Dart
49 lines
1.3 KiB
Dart
|
|
import 'dart:io';
|
||
|
|
import 'package:dio/dio.dart';
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'dio_client.dart';
|
||
|
|
|
||
|
|
class UserProfileService {
|
||
|
|
late final Dio _dio;
|
||
|
|
|
||
|
|
UserProfileService(BuildContext context) {
|
||
|
|
_dio = DioClient.getInstance(context);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Get profile
|
||
|
|
Future<Map<String, dynamic>> getProfile() async {
|
||
|
|
try {
|
||
|
|
final res = await _dio.get('/user/profile');
|
||
|
|
return Map<String, dynamic>.from(res.data);
|
||
|
|
} catch (e) {
|
||
|
|
return {"success": false, "message": e.toString()};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Update profile IMAGE only
|
||
|
|
Future<Map<String, dynamic>> updateProfileImage(File image) async {
|
||
|
|
try {
|
||
|
|
final form = FormData.fromMap({
|
||
|
|
"profile_image": await MultipartFile.fromFile(image.path),
|
||
|
|
});
|
||
|
|
|
||
|
|
final res = await _dio.post('/user/profile-image', data: form);
|
||
|
|
return Map<String, dynamic>.from(res.data);
|
||
|
|
|
||
|
|
} catch (e) {
|
||
|
|
return {"success": false, "message": e.toString()};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Send profile update request (admin approval needed)
|
||
|
|
Future<Map<String, dynamic>> sendUpdateRequest(Map<String, dynamic> data) async {
|
||
|
|
try {
|
||
|
|
final res = await _dio.post('/user/profile-update-request', data: data);
|
||
|
|
return Map<String, dynamic>.from(res.data);
|
||
|
|
|
||
|
|
} catch (e) {
|
||
|
|
return {"success": false, "message": e.toString()};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|