Flutter Json Encode List
Add toJson
method to your Player
class:
Map<String, dynamic> toJson(){ return { "name": this.name, "imagePath": this.imagePath, "totalGames": this.totalGames, "points": this.points };}
Then you can call jsonEncode
on the list of players:
String encoded = jsonEncode(players) // this will automatically call toJson on each player