title: how to load Json to flutter listview
body: <p>I'm new to flutter and I'm developing a flutter app where I have to show in a listView the data on the database.</p>
  
  <p>I get the data in JSON format.</p>
  
  <pre><code>{
      "data": [
          {
              "id": “1”,
              "testo": "Fare la spesa",
              "stato": "1"
          },
          {
              "id": “2”,
              "testo": "Portare fuori il cane",
              "stato": "1"
          },
          {
              "id": “3”,
              "testo": “jhon”,
              "stato": "0"
          }
      ]
  }
  </code></pre>
  
  <p>The problem is that I don't load the data, I can't understand how to do it.</p>
  
  <p>I should read 'Data' with an array but I don't know how to do it.</p>
  
  <p>Can anyone help me figure out how to do it?</p>
  
  <p>Thanks for your help.</p>
  
  <p>PS. I tried <a href="https://flutter.dev/docs/cookbook/networking/fetch-data" rel="nofollow noreferrer">this</a> tutorial</p>
  
  <p><strong>Main.dart</strong></p>
  
  <pre><code>Future&lt;Post&gt; fetchPost() async {
    final response =
    await http.get('http://simone.fabriziolerose.it/index.php/Hello/dispdataflutter');
  
    if (response.statusCode == 200) {
      // If the call to the server was successful, parse the JSON.
      return Post.fromJson(json.decode(response.body));
    } else {
      // If that call was not successful, throw an error.
      throw Exception('Failed to load post');
    }
  }
  
  class Post {
    final int id;
    final String title;
    final String body;
  
    Post({ this.id, this.title, this.body});
  
    factory Post.fromJson(Map&lt;String, dynamic&gt; json) {
      return Post(
  
        id: json['id'],
        title: json['testo'],
        body: json['stato'],
      );
    }
  }
  
  void main() =&gt; runApp(MyApp(post: fetchPost()));
  
  class MyApp extends StatelessWidget {
    final Future&lt;Post&gt; post;
  
    MyApp({Key key, this.post}) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Fetch Data Example',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: Scaffold(
          appBar: AppBar(
            title: Text('Fetch Data Example'),
          ),
          body: Center(
            child: FutureBuilder&lt;Post&gt;(
              future: post,
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  return Text(snapshot.data.title);
                } else if (snapshot.hasError) {
                  return Text("${snapshot.error}");
                }
  
                // By default, show a loading spinner.
                return CircularProgressIndicator();
              },
            ),
          ),
        ),
      );
    }
  }
  </code></pre>