title: Unhandled Exception: NoSuchMethodError: The method '[]' was called on null. while parsing json
body: <p>i have a json object that includes an object that could be null.
  here is my json:</p>
  <pre><code>I/flutter (23570): ║    {
  I/flutter (23570): ║         elements: [
  I/flutter (23570): ║            {
  I/flutter (23570): ║                 id: 1,
  I/flutter (23570): ║                 name: &quot;a1&quot;,
  I/flutter (23570): ║                 owner: {firstName: امین, lastName: جمالی, mobile: 9014523821}
  I/flutter (23570): ║            },
  I/flutter (23570): ║          {id: 2, name: a2}
  I/flutter (23570): ║         ],
  I/flutter (23570): ║         totalElements: 2
  I/flutter (23570): ║    }
  </code></pre>
  <p>owner filed in first element has data and in second one is empty.
  here is my view model:</p>
  <pre><code>class UnitItemViewModel {
  
  
  final int id;
    final String name;
    UnitOwner? owner;
  
    UnitItemViewModel({
      required this.id,
      required this.name,
      this.owner,
    });
  
    factory UnitItemViewModel.fromJson(final Map&lt;String, dynamic&gt; json) =&gt;
        UnitItemViewModel(
          id: json['id'],
          name: json['name'],
          owner: UnitOwner.fromJson(json['owner']),
        );
  }
  class UnitOwner {
  
  
  final String firstName, lastName;
    final String mobile;
  
    UnitOwner({
      required this.firstName,
      required this.lastName,
      required this.mobile,
    });
  
    factory UnitOwner.fromJson(final Map&lt;String, dynamic&gt; json) =&gt; UnitOwner(
          firstName: json['firstName'],
          lastName: json['lastName'],
          mobile: json['mobile'],
        );
  }
  </code></pre>
  <p>while parsing i got this exception:</p>
  <pre><code>E/flutter (23570): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 
  
  NoSuchMethodError: The method '[]' was called on null.
  E/flutter (23570): Receiver: null
  E/flutter (23570): Tried calling: [](&quot;firstName&quot;)
  </code></pre>
  <p>and here is my repository:</p>
  <pre><code>final items = (data['elements'] as List)
          .map((final e) =&gt; UnitItemViewModel.fromJson(
                e as Map&lt;String, dynamic&gt;,
              ))
          .toList();
  </code></pre>
  <p>any idea will be great.</p>