I have two forms which updates a non-observable User model on the form input's onChanged
. Along with this, I have a state enum (observable) which determines whether or not the user is registering/logging in.
The login controller roughly has this implementation
class LoginController extends GetxController {
Rx<LoginState> loginState = LoginState.notLoggedIn.obs;
UserModel userModel = UserModel();
bool get isLoggingIn => loginState.value == LoginState.loggingIn;
bool get shouldDisableLoginFormSubmit =>
isLoggingIn || !userModel.email.isEmail || userModel.password.isEmpty;
...
}
In the login form, I have a button with an isDisabled
property as one of the children of a Column
widget
Rough implementation of the form
class LoginForm extends StatelessWidget {
LoginForm({Key? key}) : super(key: key);
LoginController loginController = Get.find<LoginController>();
@override
Widget build(BuildContext context) {
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
...
Obx(() => InputTextFormField(
onChanged: _onEmailFormInputChanged,
inputType: TextInputType.emailAddress,
isDisabled: loginController.isLoggingIn)),
...
Obx(() => GenericRoundedGradientButton(
isDisabled: loginController.shouldDisableLoginFormSubmit,
onPressed: loginController.signInWithEmail)),
]);
}
}
The LoginWithEmailButton
is rebuilding on each form input change, which is what I want.
A similar approach to the registration form however, shows that the RegisterWithEmailButton
is not rebuilding on the form input's onChanged
.
Registration controller:
class RegisterController extends GetxController {
Rx<RegisterState> registerState = RegisterState.notRegistered.obs;
UserModel userModel = UserModel();
bool get isRegistering => registerState.value == RegisterState.registering;
bool get shouldDisableRegisterFormSubmit =>
isRegistering ||
userModel.fullName.isEmpty ||
!userModel.email.isEmail ||
userModel.password.isEmpty;
...
}
And the registration form:
class RegisterForm extends StatelessWidget {
RegisterForm({
Key? key,
}) : super(key: key);
RegisterController registerController = Get.find<RegisterController>();
@override
Widget build(BuildContext context) {
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Obx(() => InputTextFormField(
onChanged: _onEmailFormInputChanged,
inputType: TextInputType.email,
isDisabled: registerController.isRegistering)),
...
Obx(() => GenericRoundedGradientButton(
isDisabled: registerController.shouldDisableRegisterFormSubmit,
onPressed: registerController.registerWithEmail))
]);
}
}
However, the register with email button does not update its state. Both controllers are initialised in a previous page and kept as permanent. Has anyone faced this sort of issue before?