title: How to get JSON data from an API in flutter
body: <p>I'm facing the same issue since i start coding yesterday on my project which has a part of getting some of json data from a given api.</p>
  
  <p>My api link is: <a href="http://alkadhum-col.edu.iq/wp-json/wp/v2/posts?_embed" rel="nofollow noreferrer">http://alkadhum-col.edu.iq/wp-json/wp/v2/posts?_embed</a> <br><br>
  I'm working on flutter SDK and i'm confused why it is not working with me!, my job is to get only link, title, and source_url objects but i cannot get it. </p>
  
  <p>I tried the following code in flutter documentation<br>
  <a href="https://flutter.dev/docs/cookbook/networking/fetch-data" rel="nofollow noreferrer">https://flutter.dev/docs/cookbook/networking/fetch-data</a>
  and after some of modification according to my needs didn't got any data.<br></p>
  
  <pre><code>import 'dart:async';
  import 'dart:convert';
  import 'package:flutter/material.dart';
  import 'package:http/http.dart' as http;
  
  Future&lt;Post&gt; fetchPost() async {
    final response =
        await http.get('http://alkadhum-col.edu.iq/wp-json/wp/v2/posts/');
  
    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;
    String title;
    String link;
  
  
    Post({this.id, this.title, this.link});
  
    factory Post.fromJson(Map&lt;String, dynamic&gt; json) {
      return Post(
        id: json['id'],
        title: json['title'].toString(),
        link: json['link'].toString()
      );
    }
  }
  
  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.link);
                } else if (snapshot.hasError) {
                  return Text("${snapshot.error}");
                }
  
                // By default, show a loading spinner
                return CircularProgressIndicator();
              },
            ),
          ),
        ),
      );
    }
  }
  </code></pre>
  
  <p>I only got the meesage below:<br>
  <b>Type List dynamic is not a subtype of type Map String, dynamic </b><br><br></p>
  
  <p>Any help will be appreciated. <br>
  Thanks in advance.</p>