title: How to fix " [ERROR: The method '[]' was called on null. E/flutter (18386): Receiver: null"flutter
body: <pre class="lang-dart prettyprint-override"><code>import 'dart:async';
  import 'dart:convert';
  import 'dart:io';
  import 'package:dio/dio.dart';
  import 'package:flutter/material.dart';
  import 'package:flutter/services.dart';
  import 'Models/UserData.dart';
  
  class LoginScreen extends StatefulWidget {
    static const String id = '/login_screen';
  
    @override
    State&lt;StatefulWidget&gt; createState() {
      return _LoginPageState();
    }
  }
  
  class _LoginPageState extends State&lt;LoginScreen&gt; {
  
    static var url = "url";
  
    static BaseOptions options = BaseOptions(
        baseUrl: url,
        responseType: ResponseType.plain,
        connectTimeout: 30000,
        receiveTimeout: 30000,
        validateStatus: (code) {
          if (code &gt;= 200) {
            return true;
          }
        });
  
    static Dio dio = Dio(options);
  
    GlobalKey&lt;ScaffoldState&gt; _scaffoldKey = GlobalKey&lt;ScaffoldState&gt;();
  
    TextEditingController _emailController = TextEditingController();
  
    TextEditingController _passwordController = TextEditingController();
  
    UserData userData;
  
    @override
    void initState() {
      SystemChrome.setEnabledSystemUIOverlays([]);
      userData = UserData();
      super.initState();
    }
  
    Future&lt;Map&lt;String, dynamic&gt;&gt; _loginUser(String email, String password, String version) async {
      try {
        Options options = Options(
          contentType: ContentType.parse('application/json'),
        );
  
        final Response response = await dio.post&lt;Map&lt;String, dynamic&gt;&gt;(url + '/users/login',
            data: {'login': _emailController, 'pwd': _passwordController, 'version' :'2.0'}, options: options);
  
        print(url + '/users/login');
  
        if (response.statusCode == 200 || response.statusCode == 201) {
          return json.decode(response.data);
        } else if (response.statusCode == 401) {
          throw Exception("Incorrect Email/Password");
        } else
          throw Exception('Authentication Error');
      } on DioError catch (exception) {
        if (exception == null ||
            exception.toString().contains('SocketException')) {
          throw Exception("Network Error");
        } else if (exception.type == DioErrorType.RECEIVE_TIMEOUT ||
            exception.type == DioErrorType.CONNECT_TIMEOUT) {
          throw Exception(
              "Could'nt connect, please ensure you have a stable network.");
        } else {
          return null;
        }
      }
    }
  
    @override
    Widget build(BuildContext context) {
      bool _isLoading = false;
      String version = '2.0';
      bool _obscureText = true;
  
      return Scaffold(
        body: SingleChildScrollView(
          child: Column(
            children: &lt;Widget&gt;[
              Container(
                width: MediaQuery
                    .of(context)
                    .size
                    .width,
                height: MediaQuery
                    .of(context)
                    .size
                    .height / 2.5,
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    colors: [Colors.white, Colors.white],
                  ),
                  borderRadius: BorderRadius.only(
                    bottomLeft: Radius.circular(90),
                  ),
                ),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: &lt;Widget&gt;[
                    Spacer(),
                    Align(
                      alignment: Alignment.center,
                      child: Image.asset('assets/logo.png'),
                    ),
                    Spacer(),
                    Align(
                      alignment: Alignment.bottomRight,
                      child: Padding(
                        padding: const EdgeInsets.only(bottom: 32, right: 32),
                        child: Text(
                          'Customer App',
                          style: TextStyle(color: Colors.red, fontSize: 18),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                color: Colors.white,
                height: MediaQuery
                    .of(context)
                    .size
                    .height / 1,
                width: MediaQuery
                    .of(context)
                    .size
                    .width,
                padding: EdgeInsets.only(top: 20),
                child: Column(
                  children: &lt;Widget&gt;[
                    Container(
                      width: MediaQuery
                          .of(context)
                          .size
                          .width / 1.2,
                      height: 45,
                      padding:
                      EdgeInsets.only(top: 2, left: 16, right: 16, bottom: 2),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(50)),
                          color: Colors.white,
                          boxShadow: [
                            BoxShadow(color: Colors.red, blurRadius: 5)
                          ]),
                      child: TextField(
                        controller: _emailController,
                        decoration: InputDecoration(
                          errorText: _isLoading ? 'Value Can\'t Be Empty' : null,
                          border: InputBorder.none,
                          icon: Icon(
                            Icons.email,
                            color: Colors.red,
                          ),
                          hintText: 'Email',
                        ),
                        keyboardType: TextInputType.emailAddress,
                      ),
                    ),
                    const SizedBox(
                      width: 42.0,
                      height: 20.0,
                    ),
                    Container(
                      width: MediaQuery
                          .of(context)
                          .size
                          .width / 1.2,
                      height: 45,
                      padding:
                      EdgeInsets.only(top: 2, left: 16, right: 16, bottom: 2),
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(50)),
                          color: Colors.white,
                          boxShadow: [
                            BoxShadow(color: Colors.red, blurRadius: 8)
                          ]),
                      child: TextField(
                        obscureText: _obscureText,
                        controller: _passwordController,
                        inputFormatters: [LengthLimitingTextInputFormatter(10)],
                        decoration: InputDecoration(
                          border: InputBorder.none,
                          icon: Icon(
                            Icons.lock_open,
                            color: Colors.red,
                          ),
                          hintText: 'Password',
                        ),
                        keyboardType: TextInputType.text,
                      ),
                    ),
                    Container(
                      height: 45,
                      margin: EdgeInsets.only(top: 22),
                      width: MediaQuery
                          .of(context)
                          .size
                          .width / 1.2,
                      decoration: BoxDecoration(
                          color: Colors.red,
                          borderRadius: BorderRadius.all(Radius.circular(50))),
                      child: Center(
                        child: InkWell(
                          onTap: () async {
                            FocusScope.of(context).requestFocus(new FocusNode());
                            setState(() =&gt; _isLoading = true,);
                            Navigator.of(context)
                                  .pushReplacementNamed('/home_screen');
                            var res = await _loginUser(
                                _emailController.text, _passwordController.text,version);
                            final UserData users = UserData.fromJson(res);
                            List&lt;Map&gt; items = json.decode("response.body");
                            List&lt;UserData&gt; listOfDesig = items.map((json) =&gt; UserData.fromJson(json)).toList();
                            if (listOfDesig != null) {
                              Navigator.of(context)
                                  .pushReplacementNamed('/home_screen');
                            } else {
                              Scaffold.of(context).showSnackBar(
                                  SnackBar(content: Text("Wrong email")));
                            }
                          },
                          child: Text(
                            'Login'.toUpperCase(),
                            style: TextStyle(
                                color: Colors.white, fontWeight: FontWeight.bold),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Align(
                alignment: Alignment.center,
                child: Padding(
                  padding: const EdgeInsets.only(top: 20, right: 0),
                  child: Text(
                    'Forgot Password ?',
                    style: TextStyle(color: Colors.grey),
                  ),
                ),
              ),
            ],
          ),
        ),
      );
    }
  }
  class UserData {
    String customerid;
    String profileid;
    String branch;
    String bookername;
    String emailid;
    String mobileno;
    int cutofftime;
    String ppnames;
    String paymenttype;
    String usertype;
    int ptopCutoffTime;
    String designation;
    String designationid;
  
    UserData({
      this.customerid,
      this.profileid,
      this.branch,
      this.bookername,
      this.emailid,
      this.mobileno,
      this.cutofftime,
      this.ppnames,
      this.paymenttype,
      this.usertype,
      this.ptopCutoffTime,
      this.designation,
      this.designationid,
    });
  
    factory UserData.fromJson(Map&lt;String, dynamic&gt; json) =&gt; UserData(
      customerid: json["customerid"],
      profileid: json["profileid"],
      branch: json["branch"],
      bookername: json["bookername"],
      emailid: json["emailid"],
      mobileno: json["mobileno"],
      cutofftime: json["cutofftime"],
      ppnames: json["ppnames"],
      paymenttype: json["paymenttype"],
      usertype: json["usertype"],
      ptopCutoffTime: json["ptopCutoffTime"],
      designation: json["designation"],
      designationid: json["designationid"],
    );
  }
  
  </code></pre>
  
  <p>This is my flutter code and I'm new to flutter.</p>
  
  <p><strong>Error Message -</strong></p>
  
  <blockquote>
    <p>[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception:
    NoSuchMethodError: The method '[]' was called on null. E/flutter
    (18386): Receiver: null E/flutter (18386): Tried calling:
     E/flutter (18386): #0      Object.noSuchMethod
    (dart:core-patch/object_patch.dart:50:5) E/flutter (18386): #1<br>
    new UserData.fromJson
    (package:/Models/UserData.dart:33:21)</p>
  </blockquote>