fixed login bug

This commit is contained in:
amirrezaghabeli
2025-08-21 10:59:28 +03:30
parent e5295e0eea
commit f81e9dd32d
4 changed files with 21 additions and 6 deletions
+4 -1
View File
@@ -41,7 +41,9 @@ List<SingleChildWidget> get apiClients {
create: (context) => TenderDetailService(networkManager: context.read()), create: (context) => TenderDetailService(networkManager: context.read()),
), ),
Provider(create: (context) => YourTendersService(networkManager: context.read())), Provider(
create: (context) => YourTendersService(networkManager: context.read()),
),
Provider( Provider(
create: (context) => TendersService(networkManager: context.read()), create: (context) => TendersService(networkManager: context.read()),
), ),
@@ -103,6 +105,7 @@ List<SingleChildWidget> get viewModels {
(context) => ProfileViewModel( (context) => ProfileViewModel(
profileRepository: context.read(), profileRepository: context.read(),
authRepository: context.read(), authRepository: context.read(),
authViewModel: context.read(),
), ),
), ),
]; ];
+7 -1
View File
@@ -74,6 +74,12 @@ class AuthViewModel with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> localLogout() async {
await _authRepository.localLogout();
_loggedInUser = null;
notifyListeners();
}
Future<void> logout() async { Future<void> logout() async {
_errorMessage = null; _errorMessage = null;
notifyListeners(); notifyListeners();
@@ -82,7 +88,7 @@ class AuthViewModel with ChangeNotifier {
switch (result) { switch (result) {
case Ok<LogoutResponse>(): case Ok<LogoutResponse>():
_loggedInUser = null; localLogout();
break; break;
case Error<LogoutResponse>(): case Error<LogoutResponse>():
_errorMessage = result.error.toString(); _errorMessage = result.error.toString();
+9 -3
View File
@@ -8,16 +8,20 @@ import '../core/utils/result.dart';
import '../data/repositories/profile_repository.dart'; import '../data/repositories/profile_repository.dart';
import '../data/services/model/logout_response/logout_response.dart'; import '../data/services/model/logout_response/logout_response.dart';
import '../data/services/model/profile_response/profile_response.dart'; import '../data/services/model/profile_response/profile_response.dart';
import 'auth_view_model.dart';
class ProfileViewModel with ChangeNotifier { class ProfileViewModel with ChangeNotifier {
final ProfileRepository _profileRepository; final ProfileRepository _profileRepository;
final AuthRepository _authRepository; final AuthRepository _authRepository;
final AuthViewModel _authViewModel;
ProfileViewModel({ ProfileViewModel({
required ProfileRepository profileRepository, required ProfileRepository profileRepository,
required AuthRepository authRepository, required AuthRepository authRepository,
required AuthViewModel authViewModel,
}) : _profileRepository = profileRepository, }) : _profileRepository = profileRepository,
_authRepository = authRepository { _authRepository = authRepository,
_authViewModel = authViewModel {
getCompanyProfile(); getCompanyProfile();
} }
@@ -81,7 +85,7 @@ class ProfileViewModel with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> logout(BuildContext context) async { Future<void> logout() async {
_errorMessage = null; _errorMessage = null;
notifyListeners(); notifyListeners();
@@ -89,13 +93,15 @@ class ProfileViewModel with ChangeNotifier {
switch (result) { switch (result) {
case Ok<LogoutResponse>(): case Ok<LogoutResponse>():
localLogout(); _authViewModel.localLogout();
_loggedOut = true;
break; break;
case Error<LogoutResponse>(): case Error<LogoutResponse>():
_errorMessage = result.error.toString(); _errorMessage = result.error.toString();
break; break;
} }
notifyListeners();
_errorMessage = null; _errorMessage = null;
notifyListeners(); notifyListeners();
} }
+1 -1
View File
@@ -135,7 +135,7 @@ class _MobileProfilePageState extends State<MobileProfilePage> {
SizedBox(height: 24.0.h()), SizedBox(height: 24.0.h()),
Spacer(), Spacer(),
InkWell( InkWell(
onTap: () => viewModel.logout(context), onTap: () => viewModel.logout(),
child: Container( child: Container(
width: double.infinity, width: double.infinity,
height: 56.0.h(), height: 56.0.h(),