skip to Main Content

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


  1. In my opinion, your email is not initialized before using it.

    Instead late TextEditingController email;,

    try changing it to
    TextEditingController email = TextEditingController();

    Login or Signup to reply.
  2. Based on the error message, I guess it is coming while using !. here

     checkemail() async  {
        if (formstate.currentState!.validate()){
           statusRequest = StatusRequest.loading; 
    

    You can do null check or just provide default value as false on null case like

     checkemail() async  {
        final isValided  = formstate.currentState?.validate()??false;
        if (isValided){
           statusRequest = StatusRequest.loading; 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search