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