Issue
I am using GetX. I need once the user type a letter i get this letter to associate it to an object. But the issues is when i use ever function inside onInit fuction inside the controller, there is no change happen. so the even function never implemented.
The Controller Class Code Is:
class RegistrationController extends GetxController {
// Email
late Rx<TextEditingController> emailEditionController;
Rx<Email>? email;
@override
void onInit() {
emailEditionController = TextEditingController().obs;
ever(
emailEditionController,
(_) {
print("\n checked \n");
return email = Email(email: emailEditionController.value.text).obs;
},
);
super.onInit();
}
}
Solution
onInit fires when your controller gets initialize only for once that will not call again until you force it or reinitialize your controller. So put your functions outside of it and Try using code below :
class RegistrationController extends GetxController {
// Email
Rx<TextEditingController> emailEditionController = TextEditingController().obs;
Rx<Email>? email;
@override
void onInit() {
super.onInit();
}
ever(String val) {
print("\n checked $val\n");
return email?.value = Email(email: val); OR Email(email: emailEditionController.value.text);
}
}
On TextField Side
TextFormField(
controller: cont.emailEditionController.value,
onChanged: (val){
cont.ever(val);
},
)
Answered By - Diwyansh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.