connect with backend
This commit is contained in:
48
lib/services/user_profile_service.dart
Normal file
48
lib/services/user_profile_service.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
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()};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user