fixed logout at refresh failed

This commit is contained in:
amirrezaghabeli
2026-04-16 16:36:55 +03:30
parent 41bba5d32c
commit cc0032b21d
12 changed files with 475 additions and 344 deletions
+73 -59
View File
@@ -50,76 +50,90 @@ class _LoginMobilePageState extends State<LoginMobilePage> {
child: Center(
child: SingleChildScrollView(
padding: EdgeInsets.symmetric(horizontal: 24.0.w()),
child: Consumer<AuthViewModel>(
builder: (context, viewModel, _) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
// LoginLogo(width: 190.0.w(), height: 88.0.h()),
Padding(
padding: EdgeInsets.symmetric(horizontal: 22.0.w()),
child: SvgPicture.asset(
AssetsManager.logoBig,
width: double.infinity,
height: 50.0.h(),
),
),
SizedBox(height: 32.0.h()),
const LoginTitle(),
SizedBox(height: 32.0.h()),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// LoginLogo(width: 190.0.w(), height: 88.0.h()),
Padding(
padding: EdgeInsets.symmetric(horizontal: 22.0.w()),
child: SvgPicture.asset(
AssetsManager.logoBig,
width: double.infinity,
height: 50.0.h(),
),
),
SizedBox(height: 32.0.h()),
const LoginTitle(),
SizedBox(height: 32.0.h()),
LoginTextField(
controller: viewModel.usernameController,
focusNode: viewModel.usernameFocus,
label: LoginStrings.usernameLabel,
iconPath: AssetsManager.userIcon,
),
SizedBox(height: 16.0.h()),
LoginTextField(
controller: viewModel.usernameController,
focusNode: viewModel.usernameFocus,
label: LoginStrings.usernameLabel,
iconPath: AssetsManager.userIcon,
),
SizedBox(height: 16.0.h()),
LoginTextField(
Selector<AuthViewModel, bool>(
selector: (_, vm) => vm.obscurePassword,
builder: (_, obscurePassword, __) {
return LoginTextField(
controller: viewModel.passwordController,
focusNode: viewModel.passwordFocus,
label: LoginStrings.passwordLabel,
iconPath: AssetsManager.passwordIcon,
isPassword: true,
obscureText: viewModel.obscurePassword,
obscureText: obscurePassword,
onToggleVisibility: viewModel.togglePasswordVisibility,
),
SizedBox(height: 32.0.h()),
);
},
),
SizedBox(height: 32.0.h()),
if (viewModel.isLoading)
BaseButton(
isEnabled: false,
onPressed: null,
isLoading: true,
textColor: AppColors.white,
)
else
BaseButton(
isEnabled: viewModel.isLoginEnabled,
onPressed: () async {
if (viewModel.isLoginEnabled) {
await viewModel.login();
}
},
),
SizedBox(height: 32.0.h()),
TextButton(
onPressed: () {
const ForgotPasswordRouteData().push(context);
/// ✅ Only this part rebuilds now
Selector<AuthViewModel, bool>(
selector: (_, vm) => vm.isLoading,
builder: (_, isLoading, __) {
return Selector<AuthViewModel, bool>(
selector: (_, vm) => vm.isLoginEnabled,
builder: (_, isEnabled, __) {
if (isLoading) {
return BaseButton(
isEnabled: false,
onPressed: null,
isLoading: true,
textColor: AppColors.white,
);
}
return BaseButton(
isEnabled: isEnabled,
onPressed:
isEnabled
? () async {
await viewModel.login();
}
: null,
);
},
child: Text(
LoginStrings.forgotPassword,
style: TextStyle(
fontSize: 14.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.mainBlue,
),
),
);
},
),
SizedBox(height: 32.0.h()),
TextButton(
onPressed: () {
const ForgotPasswordRouteData().push(context);
},
child: Text(
LoginStrings.forgotPassword,
style: TextStyle(
fontSize: 14.0.sp(),
fontWeight: FontWeight.w500,
color: AppColors.mainBlue,
),
],
);
},
),
),
],
),
),
),