connect with backend

This commit is contained in:
Abhishek Mali
2025-12-03 11:57:05 +05:30
parent c6b4c66c10
commit 3bf27cc29d
48 changed files with 2618 additions and 126 deletions

View 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;
}
}