added company profile and fixed some parts

This commit is contained in:
amirrezaghabeli
2025-08-20 14:46:06 +03:30
parent 266d974786
commit 37f4b20bfa
14 changed files with 844 additions and 66 deletions
+26 -1
View File
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:tm_app/data/repositories/auth_repository.dart';
import 'package:tm_app/data/services/model/company_profile_data/company_profile_data.dart';
import 'package:tm_app/data/services/model/company_profile_response/company_profile_response.dart';
import 'package:tm_app/data/services/model/profile_data/profile_data.dart';
import '../core/utils/result.dart';
@@ -16,18 +18,20 @@ class ProfileViewModel with ChangeNotifier {
required AuthRepository authRepository,
}) : _profileRepository = profileRepository,
_authRepository = authRepository {
getProfile();
getCompanyProfile();
}
bool _isLoading = false;
String? _errorMessage;
ProfileData? _profileData;
CompanyProfileData? _companyProfileData;
bool _loggedOut = false;
bool get isLoading => _isLoading;
bool get loggedOut => _loggedOut;
String? get errorMessage => _errorMessage;
ProfileData? get profileData => _profileData;
CompanyProfileData? get companyProfileData => _companyProfileData;
Future<void> getProfile() async {
_isLoading = true;
@@ -50,6 +54,27 @@ class ProfileViewModel with ChangeNotifier {
notifyListeners();
}
Future<void> getCompanyProfile() async {
_isLoading = true;
_errorMessage = null;
notifyListeners();
final result = await _profileRepository.getCompanyProfile();
switch (result) {
case Ok<CompanyProfileResponse>():
_companyProfileData = result.value.data;
break;
case Error<CompanyProfileResponse>():
_errorMessage = result.error.toString();
break;
}
_isLoading = false;
notifyListeners();
_errorMessage = null;
notifyListeners();
}
Future<void> localLogout() async {
await _authRepository.localLogout();
_loggedOut = true;