title: Accessing quicktype JSON object in flutter
body: <p>I have a JSON string that is mapped with code generated in quicktype, into an instance of &quot;Pax&quot;. Quicktype generated some 4000 rows of code mapping this so Im happy and confident that it works to some extent. I now want to print a specific small part of this sea of data to start with. It's a string located at pax.instructions.id.</p>
  <pre><code>final String paxRaw = response.body;
  final Pax xa = paxFromJson(paxRaw);
  </code></pre>
  <pre><code>    import 'dart:convert';
      
      Pax paxFromJson(String str) =&gt; Pax.fromJson(json.decode(str));
      
      String paxToJson(Pwa data) =&gt; json.encode(data.toJson());
      
      class Pax {
        Pax({
          this.greeting,
          this.instructions,
        });
      
        String greeting;
        List&lt;Instruction&gt; instructions;
      
        factory Pax.fromRawJson(String str) =&gt; Pax.fromJson(json.decode(str));
      
        String toRawJson() =&gt; json.encode(toJson());
      
        factory Pax.fromJson(Map&lt;String, dynamic&gt; json) =&gt; Pax(
          greeting: json[&quot;greeting&quot;] == null ? null : json[&quot;greeting&quot;],
          instructions: json[&quot;instructions&quot;] == null ? null : List&lt;Instruction&gt;.from(json[&quot;instructions&quot;].map((x) =&gt; Instruction.fromJson(x))),
        );
      
        Map&lt;String, dynamic&gt; toJson() =&gt; {
          &quot;greeting&quot;: greeting == null ? null : greeting,
          &quot;instructions&quot;: instructions == null ? null : List&lt;dynamic&gt;.from(instructions.map((x) =&gt; x.toJson())),
        };
      }
  </code></pre>
  <p>I want to access a data member of the list <em>instructions</em> that is called <em>id</em>.</p>
  <pre><code>print(xa);
  </code></pre>
  <p>Returns console:</p>
  <pre><code>I/flutter ( 4535): Instance of 'Pax'
  </code></pre>
  <p>I know instructions is a list, but how do I acess the string that is called id in this list? My best guess is
  <code>print(xa.instructions&lt;id&gt;);</code> but it doesn't work. There's clearly something built, but I can't figure out how to inspect &quot;xa&quot; on a debug level (in android studio). Helpful for guidance.</p>
  <p><strong>UPDATE, still not working</strong></p>
  <pre><code>  Future&lt;Pax&gt; _futurePax;
  
    Future&lt;Pax&gt; getPax() async {
      debugPrint(&quot;getPax start&quot;);
  [...]
      http.Response response = await http.get(baseUri);
      debugPrint('Response status: ${response.statusCode}');
      debugPrint(response.body);
      return Pax.fromJson(json.decode(response.body));
    }
    @override
    void initState(){
      super.initState();
      setState(() {
        _futurePax = getPax();
      });
    }
  </code></pre>
  <pre><code>Container (
                  child: FutureBuilder&lt;Pax&gt; (
                      future: _futurePax,
                      builder: (context, snapshot) {
                        debugPrint(&quot;Futurebuilder&lt;Pax&gt; buildpart&quot;);
                        debugPrint(&quot;Test snapshot content: ${snapshot.data.toString()}&quot;);
                        debugPrint(&quot;Test snapshot error: ${snapshot.error}&quot;);
                        debugPrint(&quot;Test snapshot has data (bool): ${snapshot.hasData}&quot;);
                        debugPrint(snapshot.data.instructions[0].id);
                        return Text(&quot;Snap: ${snapshot.data.instructions[0].id}&quot;);
                      }
                ),
                ),
  </code></pre>
  <p>Console:</p>
  <pre><code>Syncing files to device sdk gphone x86...
  I/flutter ( 5126): Futurebuilder&lt;Pax&gt; buildpart
  I/flutter ( 5126): Test snapshot content: Instance of 'Pax'
  I/flutter ( 5126): Test snapshot error: null
  I/flutter ( 5126): Test snapshot has data (bool): true
  
  ════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
  The following NoSuchMethodError was thrown building FutureBuilder&lt;Pax&gt;(dirty, state: _FutureBuilderState&lt;Pax&gt;#a2168):
  The method '[]' was called on null.
  Receiver: null
  Tried calling: [](0)
  </code></pre>