Dynamic Key Json Parsing In Flutter

Dynamic Key Json Parsing In Flutter :

Dynamic Key Json Parsing In Flutter
Map<String, dynamic> jsonParsed = {"2019-01-15":{"title":"Flutter","nbLike":1}, "2019-01-16":{"title":"Hey2","nbLike":0}};

    List<Event> _events = [];
    List _dates = [];
    jsonParsed.keys.forEach((String key){
      _dates.add(key);
    });

    for(int i=0; i<_dates.length; i++){
      print(_dates[i]);

      print(jsonParsed[_dates[i]]['title']);
      print(jsonParsed[_dates[i]]['nbLike']);

      final Event event = Event(
        title: jsonParsed[_dates[i]]['title'],
        nbLike: jsonParsed[_dates[i]]['nbLike'],
      );
      _events.add(event);
    }
    print(_events.toString());

class Event {
  final String title;
  final int nbLike;

  Event({this.title, this.nbLike});

  factory Event.fromJson(Map<String, dynamic> json) {
    return Event(
      title: json['title'] as String,
      nbLike: json['nbLike'] as int,
    );
  }
}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in