diff --git a/lib/presentation/settings/viewModels/forget_password_view_model.dart b/lib/presentation/settings/viewModels/forget_password_view_model.dart index 79f0d48..3bc02d6 100644 --- a/lib/presentation/settings/viewModels/forget_password_view_model.dart +++ b/lib/presentation/settings/viewModels/forget_password_view_model.dart @@ -8,6 +8,19 @@ class ForgetPasswordViewModel extends ChangeNotifier { final AuthUseCase authUseCase; + bool obscureTextNewPassword = true; + bool obscureTextConfirmPassword = true; + + void toggleNewPasswordVisibility() { + obscureTextNewPassword = !obscureTextNewPassword; + notifyListeners(); // Notify the UI about the change + } + + void toggleConfirmPasswordVisibility() { + obscureTextConfirmPassword = !obscureTextConfirmPassword; + notifyListeners(); // Notify the UI about the change + } + ForgetPasswordViewModel({required this.authUseCase}); Future forgetPassword(String email) async { @@ -44,4 +57,5 @@ class ForgetPasswordViewModel extends ChangeNotifier { isLoading = value; notifyListeners(); } + } diff --git a/lib/presentation/settings/viewModels/login_view_model.dart b/lib/presentation/settings/viewModels/login_view_model.dart index 60c45b0..e4ec912 100644 --- a/lib/presentation/settings/viewModels/login_view_model.dart +++ b/lib/presentation/settings/viewModels/login_view_model.dart @@ -16,6 +16,13 @@ class LoginViewModel extends ChangeNotifier { bool _isButtonEnabled = false; bool get isButtonEnabled => _isButtonEnabled; + bool obscureText = true; + + void togglePasswordVisibility() { + obscureText = !obscureText; + notifyListeners(); + } + void updateButtonState(String username, String password) { _isButtonEnabled = username.isNotEmpty && password.isNotEmpty; diff --git a/lib/presentation/settings/views/forget_password_page.dart b/lib/presentation/settings/views/forget_password_page.dart index 47827ee..360b7ef 100644 --- a/lib/presentation/settings/views/forget_password_page.dart +++ b/lib/presentation/settings/views/forget_password_page.dart @@ -23,20 +23,7 @@ class _ForgetPasswordPageState extends State { String? newPassword; String? confirmCode; bool confirmEnable = false; - bool _obscureTextNewPassword = true; - bool _obscureTextConfirmPassword = true; - void _toggleNewPasswordVisibility() { - setState(() { - _obscureTextNewPassword = !_obscureTextNewPassword; - }); - } - - void _toggleConfirmPasswordVisibility() { - setState(() { - _obscureTextConfirmPassword = !_obscureTextConfirmPassword; - }); - } @override void initState() { super.initState(); @@ -103,7 +90,7 @@ class _ForgetPasswordPageState extends State { // New Password Field if (viewModel.isPasswordResetting) TextFormField( - obscureText: _obscureTextNewPassword, + obscureText: viewModel.obscureTextNewPassword, decoration: InputDecoration( labelText: "New Password", hintText: "Input new password", @@ -117,9 +104,9 @@ class _ForgetPasswordPageState extends State { errorStyle: TextStyle(color: Color(0xFFB71C1C)), suffixIcon: IconButton( icon: Icon( - _obscureTextNewPassword ? Icons.visibility_off : Icons.visibility, + viewModel.obscureTextNewPassword ? Icons.visibility_off : Icons.visibility, ), - onPressed: _toggleNewPasswordVisibility, + onPressed: viewModel.toggleNewPasswordVisibility, ), ), onChanged: (text) { @@ -142,7 +129,7 @@ class _ForgetPasswordPageState extends State { if (viewModel.isPasswordResetting) TextFormField( controller: _confirmPasswordController, - obscureText: _obscureTextConfirmPassword, + obscureText: viewModel.obscureTextConfirmPassword, decoration: InputDecoration( labelText: "Re-enter Password", hintText: "Re-enter password", @@ -156,9 +143,9 @@ class _ForgetPasswordPageState extends State { errorStyle: TextStyle(color: Color(0xFFB71C1C)), suffixIcon: IconButton( icon: Icon( - _obscureTextConfirmPassword ? Icons.visibility_off : Icons.visibility, + viewModel.obscureTextConfirmPassword ? Icons.visibility_off : Icons.visibility, ), - onPressed: _toggleConfirmPasswordVisibility, + onPressed: viewModel.toggleConfirmPasswordVisibility, ), ), validator: (value) { diff --git a/lib/presentation/settings/views/login_page.dart b/lib/presentation/settings/views/login_page.dart index 8b1fa2f..0b87cdb 100644 --- a/lib/presentation/settings/views/login_page.dart +++ b/lib/presentation/settings/views/login_page.dart @@ -23,13 +23,7 @@ class _LoginPageState extends State { bool isButtonEnabled = false; final TextEditingController _usernameController = TextEditingController(); final TextEditingController _passwordController = TextEditingController(); - bool _obscureText = true; - void _togglePasswordVisibility() { - setState(() { - _obscureText = !_obscureText; - }); - } @override void initState() { @@ -147,7 +141,7 @@ class _LoginPageState extends State { // Password Field TextFormField( controller: _passwordController, - obscureText: _obscureText, // Controls whether the text is hidden + obscureText: viewModel.obscureText, // Controls whether the text is hidden decoration: InputDecoration( labelText: 'Password', errorBorder: UnderlineInputBorder( @@ -163,9 +157,9 @@ class _LoginPageState extends State { errorStyle: TextStyle(color: Color(0xFFB71C1C)), // Error text color suffixIcon: IconButton( icon: Icon( - _obscureText ? Icons.visibility_off : Icons.visibility, + viewModel.obscureText ? Icons.visibility_off : Icons.visibility, ), - onPressed: _togglePasswordVisibility, + onPressed: viewModel.togglePasswordVisibility, ), ), style: TextStyle(color: Colors.black),