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