title: How to fetch a list of maps to a calendar? [Flutter]
body: <p>I have a json object here - </p>
  
  <pre><code>{
      "error": "0",
      "message": "Got it!",
      "data": [
          {
              "status": false,
              "_id": "5e04a27692928701258b9b06",
              "group_id": "5df8aaae2f85481f6e31db59",
              "date": "2019-12-29T00:00:00.000Z",
              "title": "new task",
              "priority": 5,
              "description": "just a description",
              "tasks": [],
              "created_date": "2019-12-26T12:07:18.301Z",
              "__v": 0
          }
      ]
  }
  </code></pre>
  
  <p>I am using this plugin to implement a calendar in my application - <a href="https://github.com/aleksanderwozniak/table_calendar" rel="nofollow noreferrer">https://github.com/aleksanderwozniak/table_calendar</a>.</p>
  
  <p>I want to fetch the json objects in the format of <code>Map &lt;DateTime, List&gt;</code> (the plugin has an assertion for using  <code>Map &lt;DateTime, List&gt;</code> for displaying events) where the "date" parameter should be mapped to "title" parameter. </p>
  
  <p>the plugin uses initState to create a few hard coded events - </p>
  
  <pre><code>
   Map&lt;DateTime, List&gt; _events;
    @override
    void initState() {
      super.initState();
  
      final _selectedDay = DateTime.now();
  
  
      _events = {_selectedDay : ["event 1"]};
    }
  </code></pre>
  
  <p>Could i get some help on how to fetch a json object and convert it to a format of <code>Map&lt;DateTime, List&gt;? Fetching the data on initState to</code> _events ` should be fine.</p>
  
  <p>data model - </p>
  
  <pre><code>class Post {
    dynamic markComplete;
    dynamic groupID;
    dynamic date;
    dynamic taskName;
    dynamic taskID;
  //dynamic subtasks;
  
    dynamic priority;
    dynamic description;
  
  /// IMPLEMENT PARAMETERS AFTER CONFIRMING WITH VAMSHI
  
    Post({
      this.markComplete,
      this.groupID,
      this.taskID,
      this.date,
      this.taskName,
  //    this.subtasks,
  
      this.priority,
      this.description,
    });
  
  /// MIGHT NEED TO CHANGE JSON VALUES; CONFIRM FROM VAMSHI
    factory Post.fromJson(Map&lt;String, dynamic&gt; json) {
      return Post(
          markComplete : json['status'],
          groupID : json['group_id'],
        taskID: json["_id"],
        date : json['date'],
        taskName : json['title'],
  //      subtasks : json['subTasks'],
  
        priority : json['priority'],
        description : json['description']
      );
    }
  
  
  
    Map toMapFetch() {
      var map = new Map&lt;dynamic, dynamic&gt;();
  //    map['status'] = markComplete;
  //    map["group_id"] = taskid;
  //    map['date'] = date;
      map['title'] = taskName;
  //    map['subTasks'] = subtasks;
  //
  //    map['priority'] = priority;
  //    map['description'] = description;
  
  
      return map;
    }
  }
  
  </code></pre>
  
  <p>method to fetch - </p>
  
  <pre><code>Future&lt;Map&lt;DateTime, List&gt;&gt; getTask() async {
    Map&lt;DateTime, List&gt; mapFetch;
    String link = baseURL + fetchTodoByDate;
    var res = await http.post(Uri.encodeFull(link), headers: {"Accept": "application/json"});
    if (res.statusCode == 200) {
   // need help in creating fetch logic here
    }
  return mapFetch;
  }
  
  </code></pre>
  
  <p>data model = </p>
  
  <pre><code>class dataArray {
  //  final dynamic status;
    final dynamic id;
    final dynamic groupName;
  
  //  final dynamic description;
  //  final dynamic created_date;
  //  final dynamic v;
  
  
    dataArray(this.groupName, this.id);
  
  
    dataArray.fromJson(Map jsonMap)
        : groupName = jsonMap['name'],
          id = jsonMap['_id'];
  
  
    Map toMapData(){
      var mapGroup = new Map&lt;String, dynamic&gt;();
      mapGroup["name"] = groupName;
      mapGroup['_id'] = id;
      return mapGroup;
  
    }
  
  }
  </code></pre>
  
  <p>updated getTask method = </p>
  
  <pre><code>  Future&lt;List&lt;dataArray&gt;&gt; getTask() async {
  
  
      List&lt;dataArray&gt; groupMap;
      String link = baseURL + fetchGroups;
      var res = await http
          .get(Uri.encodeFull(link), headers: {"Accept": "application/json"});
  //  print(res.body);
      if (res.statusCode == 200) {
        var data = json.decode(res.body);
        var rest = data["data"] as List;
  
        final demoJsonMapEntries = rest.map((data) {
          return MapEntry(DateTime.parse(data['created_date']), data['name']);
        });
  
        demoJsonMapEntries.forEach((e) {
          // Normalize the `date` - this is necessary to ensure proper `Map` behavior
          final key = DateTime.utc(e.key.year, e.key.month, e.key.day, 12);
  
          _events.update(key, (list) =&gt; list..add(e.value), ifAbsent: () =&gt; [e.value]);
        });
        print(demoJsonMapEntries);
      }
      print("PRINTING MAP = $groupMap");
   return groupMap;
    }
  </code></pre>