How to encode list to json?
This is my class for Json.
class Players{
List players;
Players({this.players});
factory Players.fr
Add toJson method to your Player class:
Map 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