Skip to content

Instantly share code, notes, and snippets.

@nhancv
Created December 12, 2018 15:53
Show Gist options
  • Select an option

  • Save nhancv/7e166479b0b5c8536a216c0aeaa334cb to your computer and use it in GitHub Desktop.

Select an option

Save nhancv/7e166479b0b5c8536a216c0aeaa334cb to your computer and use it in GitHub Desktop.
Flutter user model
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