Fixed login bug after logout
This commit is contained in:
@@ -13,8 +13,8 @@ class AuthViewModel with ChangeNotifier {
|
||||
: _authRepository = authRepository {
|
||||
usernameController.addListener(_onTextChanged);
|
||||
passwordController.addListener(_onTextChanged);
|
||||
usernameFocus.addListener(_onTextChanged);
|
||||
passwordFocus.addListener(_onTextChanged);
|
||||
// usernameFocus.addListener(_onTextChanged);
|
||||
// passwordFocus.addListener(_onTextChanged);
|
||||
}
|
||||
|
||||
final TextEditingController usernameController = TextEditingController();
|
||||
@@ -58,6 +58,10 @@ class AuthViewModel with ChangeNotifier {
|
||||
switch (result) {
|
||||
case Ok<LoginResponseModel>():
|
||||
_loggedInUser = result.value.data.customer;
|
||||
usernameController.text.trim();
|
||||
passwordController.text.trim();
|
||||
usernameController.clear();
|
||||
passwordController.clear();
|
||||
break;
|
||||
case Error<LoginResponseModel>():
|
||||
_errorMessage = result.error.toString();
|
||||
@@ -70,6 +74,13 @@ class AuthViewModel with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void forceLogout() {
|
||||
_loggedInUser = null;
|
||||
usernameController.clear();
|
||||
passwordController.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tm_app/data/repositories/auth_repository.dart';
|
||||
import 'package:tm_app/data/services/model/profile_data/profile_data.dart';
|
||||
import 'package:tm_app/view_models/auth_view_model.dart';
|
||||
|
||||
import '../core/utils/result.dart';
|
||||
import '../data/repositories/profile_repository.dart';
|
||||
@@ -55,13 +57,20 @@ class ProfileViewModel with ChangeNotifier {
|
||||
_loggedOut = true;
|
||||
}
|
||||
|
||||
Future<void> logout() async {
|
||||
Future<void> logout(BuildContext context) async {
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
final result = await _authRepository.logout();
|
||||
|
||||
switch (result) {
|
||||
case Ok<LogoutResponse>():
|
||||
await localLogout();
|
||||
// دسترسی به AuthViewModel و ریست یوزر
|
||||
// چون با Provider کار میکنی:
|
||||
final authViewModel = Provider.of<AuthViewModel>(context, listen: false);
|
||||
authViewModel.forceLogout();
|
||||
_loggedOut = true;
|
||||
break;
|
||||
case Error<LogoutResponse>():
|
||||
_errorMessage = result.error.toString();
|
||||
@@ -70,5 +79,6 @@ class ProfileViewModel with ChangeNotifier {
|
||||
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class _MobileProfilePageState extends State<MobileProfilePage> {
|
||||
// ),
|
||||
SizedBox(height: 24.0.h()),
|
||||
InkWell(
|
||||
onTap: () => viewModel.logout(),
|
||||
onTap: () => viewModel.logout(context),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
height: 45.0.h(),
|
||||
|
||||
Reference in New Issue
Block a user