Created with <3 with dartpad.dev.
Created
July 10, 2023 07:53
-
-
Save kmkkkp/23a0851fd0ab96f60319abcf8e6a3c6a to your computer and use it in GitHub Desktop.
class_practice_apiData
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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