Cubit State class
class AuthState extends Equatable {
const AuthState({
this.makePwdVisible = true,
});
final bool makePwdVisible;
@override
List<Object> get props => [makePwdVisible];
AuthState copyWith({
bool? makePwdVisible,
}) {
return AuthState(
makePwdVisible: makePwdVisible ?? this.makePwdVisible,
);
}
}
Cubit class to emit state
class AuthenticationCubit extends Cubit<AuthState> {
void togglePwdVisibility() {
emit(
state.copyWith(
makePwdVisible: !state.makePwdVisible
)
);
}
}
Class Contain TextFormField to accept password
class PasswordInput extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocBuilder<AuthenticationCubit, AuthState>(
buildWhen: (previous, current) => previous.password != current.password,
builder: (context, state) {
return Padding(
child: TextFormField(
obscureText: state.makePwdVisible,
onPressed: () => context.read<AuthenticationCubit>().togglePwdVisibility()
) : null,
),
),
);
},
);
}
}
I am trying to update password visibility of TextFormField but when I click the eye button of TextFormField nothing happens. Cubit is not updating the state because state.makePwdVisible not get called on eye button toggle. While when I enter password and if password is wrong state.password.error is getting called. I don't know why Cubit is working for one variable password.error but not for makePwdVisible