title: E/flutter (32633): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The getter 'statusCode' was called on null
body: <p>E/flutter (32633): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The getter 'statusCode' was called on null.
  E/flutter (32633): Receiver: null
  E/flutter (32633): Tried calling: statusCode
  E/flutter (32633): #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
  E/flutter (32633): #1      APIService.createCustomer
  E/flutter (32633): #2      _SignupPageState._formUI.</p>
  <pre><code>    class APIService {
    Future&lt;bool&gt; createCustomer(CustomerModel model) async {
      var authToken = base64.encode(
        utf8.encode(Config.key + ':' + Config.sceret),
      );
  
      bool ret = false;
      Dio dio = Dio();
      if (Platform.isAndroid) {
        (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
            (client) {
          client.badCertificateCallback =
              (X509Certificate cert, String host, int port) =&gt; true;
          return client;
        };
      }
  
      try {
        var response = await Dio().post(Config.url + Config.customerURL,
            data: model.toJson(),
            options: new Options(headers: {
              HttpHeaders.authorizationHeader: 'Basic $authToken',
              HttpHeaders.contentTypeHeader: 'application/json'
            }));
  
        if (response.statusCode == 201) {
          ret = true;
        }
      } on DioError catch (e) {
        if (e.response.statusCode == 404) {
          ret = false;
        } else {
          ret = false;
        }
      }
      return ret;
    }
  }
  
  
  
      class SignupPage extends StatefulWidget {
    @override
    _SignupPageState createState() =&gt; _SignupPageState();
  }
  
  class _SignupPageState extends State&lt;SignupPage&gt; {
    APIService apiService;
    CustomerModel model;
    GlobalKey&lt;FormState&gt; globalKey = GlobalKey&lt;FormState&gt;();
    bool hidePassword = true;
    bool isApiCallProcess = false;
  
    @override
    void initState() {
      apiService = new APIService();
      model = new CustomerModel();
      super.initState();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.red,
          automaticallyImplyLeading: true,
          title: Text('Sign Up'),
        ),
        body: ProgressHUD(
            child: Form(
              key: globalKey,
              child: _formUI(),
            ),
            inAsyncCall: isApiCallProcess,
            opacity: 0.3),
      );
    }
  
    Widget _formUI() {
      return SingleChildScrollView(
        child: Padding(
          padding: EdgeInsets.all(10.00),
          child: Container(
            child: Align(
              alignment: Alignment.topLeft,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: &lt;Widget&gt;[
                  FormHelper.fieldLabel('First Name'),
                  FormHelper.textInput(
                    context,
                    model.firstName,
                    (value) =&gt; {
                      this.model.firstName = value,
                    },
                    onValidate: (value) {
                      if (value.toString().isEmpty) {
                        return 'Please enter First Name.';
                      }
                      return null;
                    },
                  ),
                  FormHelper.fieldLabel('Last Name'),
                  FormHelper.textInput(
                    context,
                    model.lastName,
                    (value) =&gt; {
                      this.model.lastName = value,
                    },
                    onValidate: (value) {
                      return null;
                    },
                  ),
                  FormHelper.fieldLabel('Email Id'),
                  FormHelper.textInput(
                    context,
                    model.email,
                    (value) =&gt; {
                      this.model.email = value,
                    },
                    onValidate: (value) {
                      if (value.toString().isEmpty) {
                        return 'Please enter Email id.';
                      }
                      if (value.isNotEmpty &amp;&amp; !value.toString().isValidEmail()) {
                        return 'Please enter valid email id';
                      }
                      return null;
                    },
                  ),
                  FormHelper.fieldLabel('Password'),
                  FormHelper.textInput(
                    context,
                    model.password,
                    (value) =&gt; {
                      this.model.password = value,
                    },
                    onValidate: (value) {
                      if (value.toString().isEmpty) {
                        return 'Please enter Password.';
                      }
                      return null;
                    },
                    obscureText: hidePassword,
                    suffixIcon: IconButton(
                      onPressed: () {
                        setState(() {
                          hidePassword = !hidePassword;
                        });
                      },
                      color: Theme.of(context).accentColor.withOpacity(0.4),
                      icon: Icon(
                        hidePassword ? Icons.visibility_off : Icons.visibility,
                      ),
                    ),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Center(
                    child: FormHelper.saveButton(
                      'Register',
                      () {
                        if (validateAndSave()) {
                          print(model.toJson());
                          setState(() {
                            isApiCallProcess = true;
                          });
                          apiService.createCustomer(model).then(
                            (ret) {
                              setState(() {
                                isApiCallProcess = false;
                              });
  
                              if (ret) {
                                FormHelper.showMessage(
                                  context,
                                  'WooCommerce App',
                                  'Registration Successfull',
                                  'Ok',
                                  () {
                                    Navigator.of(context).pop();
                                  },
                                );
                              } else {
                                FormHelper.showMessage(
                                  context,
                                  'WooCommerce App',
                                  'Email Id already registered.',
                                  'Ok',
                                  () {
                                    Navigator.of(context).pop();
                                  },
                                );
                              }
                            },
                          );
                        }
                      },
                    ),
                  )
                ],
              ),
            ),
          ),
        ),
      );
    }
  
    bool validateAndSave() {
      final form = globalKey.currentState;
      if (form.validate()) {
        form.save();
        return true;
      }
      return false;
    }
  }
  </code></pre>