I have this class in flutter
abstract class ForgetPasswordController extends GetxController {
checkemail();
}
class ForgetPasswordControllerImp extends ForgetPasswordController {
CheckEmailData checkEmailData = CheckEmailData(Get.find()) ;
GlobalKey<FormState> formstate = GlobalKey<FormState>();
StatusRequest? statusRequest = StatusRequest.none ;
late TextEditingController email;
@override
checkemail() async {
if (formstate.currentState!.validate()){
statusRequest = StatusRequest.loading;
update() ;
var response = await checkEmailData.postdata(email.text);
print("=============================== Controller $response ");
statusRequest = handlingData(response);
if (StatusRequest.success == statusRequest) {
if (response['status'] == "success") {
// data.addAll(response['data']);
Get.offNamed(AppRoute.verfiyCode , arguments: {
"email" : email.text
});
} else {
Get.defaultDialog(title: "ُWarning" , middleText: "Email Not Found");
statusRequest = StatusRequest.failure;
}
}
update();
}
}
@override
void onInit() {
email = TextEditingController();
super.onInit();
}
@override
void dispose() {
email.dispose();
super.dispose();
}
}
but when try this method on emulator i have error message in console says :
E/flutter ( 7876): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter ( 7876): #0 ForgetPasswordControllerImp.checkemail
package:powerecommerce/…/forgetpassword/forgetpassword_controller.dart:27
E/flutter ( 7876): #1 ForgetPassword.build..
Im just a beginner and idk how i can solve this problem
I tried to see if there is any problem with php api files but all files are correct!
and i researched for all the basic problem solving and the same problem exist
2
Answers
In my opinion, your
email
is not initialized before using it.Instead
late TextEditingController email;
,try changing it to
TextEditingController email = TextEditingController();
Based on the error message, I guess it is coming while using
!
. hereYou can do null check or just provide default value as false on null case like