title: How to convert model type of list to Map<String, List> element in flutter?
body: <p>I have model type of list.</p>
  <pre><code>Which is RxList&lt;ConsultationRequestDatum&gt; pastConsultationList =
        &lt;ConsultationRequestDatum&gt;[].obs
  </code></pre>
  <p>Now, I want to convert it into</p>
  <pre><code>Map&lt;String, List&gt; _elements = {
    'appointmentDate': ['id', 'appointment_time', 'name','age'], //appointmentDate = &quot;Today&quot;
    'appointmentDate': ['id', 'appointment_time', 'name','age'], //appointmentDate = &quot;Yesterday&quot;
    'appointmentDate': ['id', 'appointment_time', 'name','age'], //appointmentDate = &quot;4 september 2022&quot;
    'appointmentDate': ['id', 'appointment_time', 'name','age'], //appointmentDate = &quot;5 september 2022&quot;
    'appointmentDate': ['id', 'appointment_time', 'name','age']  //appointmentDate = &quot;6 september 2022&quot;
    };
  </code></pre>
  <p>How do I do it in flutter ?</p>
  <p>ConsulationRequestDatum is model. It is too long that's why I did not upload. I just want to convert list to map&lt;String, List&gt; _elements. In ConsulationRequestDatum model I have date,time,text,...and other variables. but in _elements I want date as key and other informations as values. Thank you</p>
  <pre><code>class ConsultationRequestDatum {
    ConsultationRequestDatum({
      this.id,
      this.appointmentId,
      this.appointmentDate,
      this.appointmentTime,
      this.appointmentDateTime,
      this.consultationMemberId,
      this.status,
      this.userId,
      this.name,
      this.age,
      this.gender,
      this.notificationGroupTitle
    });
  
    int? id;
    String? appointmentId;
    DateTime? appointmentDate;
    String? appointmentTime;
    DateTime? appointmentDateTime;
    int? consultationMemberId;
    int? status;
    int? userId;
    String? name;
    String? age;
    String? gender;
    String? notificationGroupTitle;
  
    factory ConsultationRequestDatum.fromJson(Map&lt;String, dynamic&gt; json) =&gt; ConsultationRequestDatum(
      id: json[&quot;id&quot;],
      appointmentId: json[&quot;appointment_id&quot;],
      appointmentDate: DateTime.parse(json[&quot;appointment_date&quot;]),
      appointmentTime: json[&quot;appointment_time&quot;],
      appointmentDateTime: DateTime.parse(json[&quot;appointment_date_time&quot;]),
      consultationMemberId: json[&quot;consultation_member_id&quot;],
      status: json[&quot;status&quot;],
      userId: json[&quot;user_id&quot;],
      name: json[&quot;name&quot;],
      age: json[&quot;age&quot;],
      gender: json[&quot;gender&quot;],
      notificationGroupTitle: json[&quot;notificationGroupTitle&quot;] == null ? null : json[&quot;notificationGroupTitle&quot;],
    );
  
    Map&lt;String, dynamic&gt; toJson() =&gt; {
      &quot;id&quot;: id,
      &quot;appointment_id&quot;: appointmentId,
      &quot;appointment_date&quot;: &quot;${appointmentDate!.year.toString().padLeft(4, '0')}-${appointmentDate!.month.toString().padLeft(2, '0')}-${appointmentDate!.day.toString().padLeft(2, '0')}&quot;,
      &quot;appointment_time&quot;: appointmentTime,
      &quot;appointment_date_time&quot;: appointmentDateTime!.toIso8601String(),
      &quot;consultation_member_id&quot;: consultationMemberId,
      &quot;status&quot;: status,
      &quot;user_id&quot;: userId,
      &quot;name&quot;: name,
      &quot;age&quot;: age,
      &quot;gender&quot;: gender,
      &quot;notificationGroupTitle&quot;: notificationGroupTitle,
    };
  
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/l7uii.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l7uii.png" alt="enter image description here" /></a></p>
  <p>appointmentDate will be used as header(date) in listview. you can see that in image. and other things are used in section items file in listview.</p>