Skip to content

Instantly share code, notes, and snippets.

@rafaelvicio
Created March 12, 2020 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelvicio/71ea29d3affe4fba182e0c56d5ca67ae to your computer and use it in GitHub Desktop.
Save rafaelvicio/71ea29d3affe4fba182e0c56d5ca67ae to your computer and use it in GitHub Desktop.
FromJson with Object in Object
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'],
);
}
}
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