Created
March 12, 2020 23:36
-
-
Save rafaelvicio/71ea29d3affe4fba182e0c56d5ca67ae to your computer and use it in GitHub Desktop.
FromJson with Object in Object
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
import 'package:news/models/player.dart'; | |
import 'game.dart'; | |
class Fantasy { | |
String id; | |
String name; | |
DateTime openAt; | |
DateTime closeAt; | |
Game game; | |
List<PLayer> players; | |
bool open; | |
bool active; | |
Fantasy({ | |
this.id, | |
this.name, | |
this.openAt, | |
this.closeAt, | |
this.game, | |
this.players, | |
this.open, | |
this.active, | |
}); | |
factory Fantasy.fromJson(Map<String, dynamic> json) { | |
return Fantasy( | |
id: json['_id'], | |
name: json['name'], | |
openAt: DateTime.parse(json['openAt']), | |
closeAt: DateTime.parse(json['closeAt']), | |
game: json['game'], //COMO FAZER ISSO AQUI? | |
players: List.from(json['players']), | |
open: json['open'], | |
active: json['active'], | |
); | |
} | |
} |
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
import 'package:news/models/article.dart'; | |
class Game { | |
String name; | |
String slug; | |
List<Article> articles = []; | |
Game({this.name, this.slug}); | |
factory Game.fromJson(Map<String, dynamic> json) { | |
return Game( | |
name: json['name'], | |
slug: json['slug'], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment