Created
December 12, 2018 15:53
-
-
Save nhancv/7e166479b0b5c8536a216c0aeaa334cb to your computer and use it in GitHub Desktop.
Flutter user model
This file contains hidden or 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:bflutter_poc/model/user_base.dart'; | |
| import 'package:json_annotation/json_annotation.dart'; | |
| part 'user.g.dart'; | |
| @JsonSerializable() | |
| class User extends UserBase { | |
| User(String login, String avatarUrl, this.name, this.location) | |
| : super(login, avatarUrl); | |
| String name; | |
| String location; | |
| /// A necessary factory constructor for creating a new User instance | |
| /// from a map. Pass the map to the generated `_$UserFromJson` constructor. | |
| /// The constructor is named after the source class, in this case User. | |
| factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json); | |
| /// `toJson` is the convention for a class to declare support for serialization | |
| /// to JSON. The implementation simply calls the private, generated | |
| /// helper method `_$UserToJson`. | |
| Map<String, dynamic> toJson() => _$UserToJson(this); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment