title: Why is one way of json to object working and the other throwing null error? Dart/Flutter null safety trouble
body: <p>I'm learning how to use json, not used to Dart null safety &amp; I don't like it so far. But I will have no choice but to adapt to it. I'm trying to parse my json object list into a list of objects. I was able to work out the basics in my main, but when I attempt to create an actual method in a class using the same structure I'm getting a null error. As far as I can tell I'm doing the exact same thing in both with addition of the loop for iterating the entire json list.</p>
  <p>Note: I of course did try inserting the optional ? where it asks but the IDE will not allow this.</p>
  <p>Can someone help with explaining what I'm doing wrong here?</p>
  <p><em><strong>Error for class method jsonToDatabaseSyncItem()</strong></em></p>
  <pre><code>lib/services/remote_database_services.dart:52:43: Error: Property 'length' cannot be accessed on 'List&lt;dynamic&gt;?' because it is potentially null.
   - 'List' is from 'dart:core'.
  Try accessing using ?. instead.
      final jsonListLength = jsonObjectList.length;
                                            ^^^^^^
  lib/services/remote_database_services.dart:55:38: Error: Operator '[]' cannot be called on 'List&lt;dynamic&gt;?' because it is potentially null.
   - 'List' is from 'dart:core'.
        var jsonObject = jsonObjectList[index]['DatabaseSyncItem'];
  
  </code></pre>
  <p><em><strong>Class method (class- RemoteDatabaseService)</strong></em></p>
  <pre><code>// This method will get server database
    Future&lt;List&lt;dynamic&gt;?&gt; getRemoteDatabase() async {
      final events = QueryBuilder&lt;ParseObject&gt;(ParseObject('Event'));
      final apiResponse = await events.query();
      if (apiResponse.success &amp;&amp; apiResponse.result != null) {
        return apiResponse.results;
      } else {
        return [];
      }
    }
  
  // Method to parse json result list back to objects
    Future&lt;List&lt;dynamic&gt;?&gt; jsonToDatabaseSyncItem() async {
      final remoteDatabaseList = await getRemoteDatabase();
      final jsonObjectList = await Future.value(remoteDatabaseList);     /// This method throws the above
      final jsonListLength = jsonObjectList.length;                      /// error when run in main
  
      for (var index = 0; index == jsonListLength; index++) {
        var jsonObject = jsonObjectList[index]['DatabaseSyncItem'];
        print(jsonObject);
      }
    }
  </code></pre>
  <p><em><strong>Main file working code</strong></em></p>
  <pre><code>Future&lt;void&gt; main(List&lt;String&gt; arguments) async {
  
  final test = remoteDatabaseServices.getRemoteDatabase();
    Future&lt;List&lt;dynamic&gt;?&gt; getList() {
      return Future.value(test);
    }
  
    var list = await getList();
    print(list?.length);
    var jsonObject = list![0]['DatabaseSyncItem'];
    print(jsonObject);
  
    var toObject = DatabaseSyncItem.fromJson(jsonObject);
    print(toObject);
  }
  </code></pre>