Skip to content

Commit

Permalink
refactoring redo (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ida631 authored Nov 7, 2024
1 parent b566e6a commit d6a9b80
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> forgetPassword(String email) async {
Expand Down Expand Up @@ -44,4 +57,5 @@ class ForgetPasswordViewModel extends ChangeNotifier {
isLoading = value;
notifyListeners();
}

}
7 changes: 7 additions & 0 deletions lib/presentation/settings/viewModels/login_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 6 additions & 19 deletions lib/presentation/settings/views/forget_password_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,7 @@ class _ForgetPasswordPageState extends State<ForgetPasswordPage> {
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();
Expand Down Expand Up @@ -103,7 +90,7 @@ class _ForgetPasswordPageState extends State<ForgetPasswordPage> {
// New Password Field
if (viewModel.isPasswordResetting)
TextFormField(
obscureText: _obscureTextNewPassword,
obscureText: viewModel.obscureTextNewPassword,
decoration: InputDecoration(
labelText: "New Password",
hintText: "Input new password",
Expand All @@ -117,9 +104,9 @@ class _ForgetPasswordPageState extends State<ForgetPasswordPage> {
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) {
Expand All @@ -142,7 +129,7 @@ class _ForgetPasswordPageState extends State<ForgetPasswordPage> {
if (viewModel.isPasswordResetting)
TextFormField(
controller: _confirmPasswordController,
obscureText: _obscureTextConfirmPassword,
obscureText: viewModel.obscureTextConfirmPassword,
decoration: InputDecoration(
labelText: "Re-enter Password",
hintText: "Re-enter password",
Expand All @@ -156,9 +143,9 @@ class _ForgetPasswordPageState extends State<ForgetPasswordPage> {
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) {
Expand Down
12 changes: 3 additions & 9 deletions lib/presentation/settings/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ class _LoginPageState extends State<NewLoginPage> {
bool isButtonEnabled = false;
final TextEditingController _usernameController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
bool _obscureText = true;

void _togglePasswordVisibility() {
setState(() {
_obscureText = !_obscureText;
});
}

@override
void initState() {
Expand Down Expand Up @@ -147,7 +141,7 @@ class _LoginPageState extends State<NewLoginPage> {
// 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(
Expand All @@ -163,9 +157,9 @@ class _LoginPageState extends State<NewLoginPage> {
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),
Expand Down

0 comments on commit d6a9b80

Please sign in to comment.