71 lines
1.5 KiB
Dart
71 lines
1.5 KiB
Dart
import 'dart:io';
|
|
import 'package:flutter/material.dart';
|
|
import '../models/user_profile.dart';
|
|
import '../services/user_profile_service.dart';
|
|
|
|
class UserProfileProvider extends ChangeNotifier {
|
|
UserProfileService? _service;
|
|
|
|
UserProfile? profile;
|
|
bool loading = false;
|
|
|
|
void init(BuildContext context) {
|
|
_service = UserProfileService(context);
|
|
}
|
|
|
|
Future<void> loadProfile(BuildContext context) async {
|
|
_service ??= UserProfileService(context);
|
|
|
|
loading = true;
|
|
notifyListeners();
|
|
|
|
final res = await _service!.getProfile();
|
|
|
|
if (res['success'] == true) {
|
|
profile = UserProfile.fromJson(res['data']);
|
|
}
|
|
|
|
loading = false;
|
|
notifyListeners();
|
|
}
|
|
|
|
Future<bool> updateProfileImage(BuildContext context, File image) async {
|
|
_service ??= UserProfileService(context);
|
|
|
|
loading = true;
|
|
notifyListeners();
|
|
|
|
final res = await _service!.updateProfileImage(image);
|
|
|
|
if (res['success'] == true) {
|
|
profile = UserProfile.fromJson(res['data']);
|
|
loading = false;
|
|
notifyListeners();
|
|
return true;
|
|
}
|
|
|
|
loading = false;
|
|
notifyListeners();
|
|
return false;
|
|
}
|
|
|
|
/// NEW: Send profile update request (admin approval required)
|
|
Future<bool> sendProfileUpdateRequest(
|
|
BuildContext context,
|
|
Map<String, dynamic> data,
|
|
) async {
|
|
_service ??= UserProfileService(context);
|
|
|
|
loading = true;
|
|
notifyListeners();
|
|
|
|
final res = await _service!.sendUpdateRequest(data);
|
|
|
|
loading = false;
|
|
notifyListeners();
|
|
|
|
return res['success'] == true;
|
|
}
|
|
}
|
|
|