Files
kent_logistics_app/lib/providers/user_profile_provider.dart

71 lines
1.5 KiB
Dart
Raw Normal View History

2025-12-03 11:57:05 +05:30
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;
}
}