title: Hello, I'm trying to figure out how factory constructor working in dart
body: <p>I've took the code from flutter.dev which use factory for fetching data from the internet.</p>
  <pre><code>import 'dart:convert';
  
  Future&lt;Album&gt; fetchAlbum() async {
    final response = await http.get('https://jsonplaceholder.typicode.com/albums/1');
  
    if (response.statusCode == 200) {
      // If the server did return a 200 OK response,
      // then parse the JSON.
      return Album.fromJson(jsonDecode(response.body));
    } else {
      // If the server did not return a 200 OK response,
      // then throw an exception.
      throw Exception('Failed to load album');
    }
  }
  
  class Album {
    final int userId;
    final int id;
    final String title;
  
    Album({this.userId, this.id, this.title});
  
    factory Album.fromJson(Map&lt;String, dynamic&gt; json) {
      return Album(
        userId: json['userId'],
        id: json['id'],
        title: json['title'],
      );
    }
  }
  </code></pre>
  <p>I had tried to repeat it in my code but it didn't work. And I'm confused why it doesn't work because I do the same as in the example.</p>
  <pre><code>Future&lt;Album&gt; fetchAlbum() {
  
    Map&lt;String, dynamic&gt; map = {
      &quot;photo&quot;: &quot;another data&quot;,
      &quot;id&quot;: &quot;dsiid1dsaq&quot;,
    };
  
    return Album.fromJson(map);
  }
  
  class Album {
  
    String photo;
    String id;
  
    Album({this.photo, this.id});
  
    factory Album.fromJson(Map&lt;String, dynamic&gt; json) {
      return Album(
        photo: json['photo'],
        id: json['id'],
      )`
    }
  }
  </code></pre>
  <p>It tells me that: &quot;A value of type 'Album' can't be returned from function 'fetchAlbum' because it has a return type of 'Future'.&quot;</p>