title: How to create objects of generic types in flutter/dart?
body: <p>How can we create object of generic types in dart? </p>
  
  <p>For my use case, each of my api responses are wrapped as <code>ApiResponse</code> class. For login api response, I get a json object such as </p>
  
  <pre><code>{
      "data": {
          "email": "a@b.com",
          "name": "A"
      },
      "message": "Successful",
      "status": true
  }
  </code></pre>
  
  <p>So to parse these responses, I created classes as below, but they throw compile time error stating that <strong>The method 'fromJson' isn't defined for the class 'Type'.</strong> :</p>
  
  <pre><code>class ApiResponse&lt;T extends BaseResponse&gt; {
    bool status;
    String message;
    T data;
  
    ApiResponse.fromJson(Map&lt;String, dynamic&gt; json) {
      status = json['status'];
      message = json['message'];
      data = T.fromJson(json['data']);  // &lt;&lt;&lt;------- here is the compile time error
    }
  }
  
  abstract class BaseResponse {
    BaseResponse.fromJson(Map&lt;String, dynamic&gt; json);
  }
  
  class Login extends BaseResponse {
    String name, email;
  
    Login.fromJson(Map&lt;String, dynamic&gt; json) : super.fromJson(json) {
      name = json['name'];
      email = json['email'];
    }
  }
  
  // and I want to use it like below
  usage() {
    ApiResponse&lt;Login&gt; a = ApiResponse.fromJson({});
    String name = a.data.name;
  }
  </code></pre>
  
  <p>Can anyone help me fix the error?</p>