title: Flutter: When should the factory constructor be used?
body: <p><a href="https://flutter.dev/docs/cookbook/networking/fetch-data" rel="noreferrer">https://flutter.dev/docs/cookbook/networking/fetch-data</a></p>
  <p>In the last 'complete example' of the above page,</p>
  <pre><code>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>It is an Album class to receive the JSON string received in the request and handle it in the application,
  The constructor provides a factory constructor in addition to the normal constructor.</p>
  <p>About the factory constructor,
  <a href="https://dart.dev/guides/language/language-tour#constructors" rel="noreferrer">https://dart.dev/guides/language/language-tour#constructors</a></p>
  <p>I have read the Factory constructors section of the above page.</p>
  <p>The factory constructor of the Logger class in the sample does not always create a new instance, so
  I can understand adding the factory keyword,</p>
  <p>Is it necessary to use the factory constructor even in the Album class of this Complete example?</p>
  <p>In the case of the Album class, since the normal constructor is used in the factory constructor,
  I feel that this factory constructor (Album.fromJson) always creates a new instance.
  In fact</p>
  <pre><code>Future&lt;Album&gt; fetchAlbum() async {
    final response =
    await http.get('https://jsonplaceholder.typicode.com/albums/16');
  
    if (response.statusCode == 200) {
      // If the server did return a 200 OK response,
      // then parse the JSON.
      var temp=json.decode(response.body);
      return Album(userId:temp['userId'],id:temp['id'],title:temp['title']);
    } else {
      // If the server did not return a 200 OK response,
      // then throw an exception.
      throw Exception('Failed to load album');
    }
  }
  </code></pre>
  <p>As you can see, it seems that it works without any problems even if I try using only the normal constructor.</p>
  <p>Is there any advantage to preparing and using a factory constructor?</p>
  <p>Or is there something wrong without using the factory constructor in this situation?</p>
  <p>I'm not sure when to use the factory constructor in the first place,
  Is there a clear definition?</p>