Skip to content

Instantly share code, notes, and snippets.

@kmkkkp
Created July 10, 2023 07:53
Show Gist options
  • Save kmkkkp/23a0851fd0ab96f60319abcf8e6a3c6a to your computer and use it in GitHub Desktop.
Save kmkkkp/23a0851fd0ab96f60319abcf8e6a3c6a to your computer and use it in GitHub Desktop.
class_practice_apiData

class_practice_apiData

Created with <3 with dartpad.dev.

class Player {
final String name;
int xp;
String team;
Player.fromJson(Map<String, dynamic> playerJson) :
name = playerJson['name'],
xp = playerJson['xp'],
team = playerJson['team'];
void sayHello(){
print("Hi my name $name");
}
}
void main(){
var apiData = [
{
"name": "nico",
"team": "red",
"xp": 0,
},
{
"name": "lynn",
"team": "red",
"xp": 0,
},
{
"name": "dal",
"team": "red",
"xp": 0,
},
];
apiData.forEach((playerJson) {
var player = Player.fromJson(playerJson);
player.sayHello();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment