Model.fromJson constructor

Model.fromJson(
  1. Map<String, dynamic> json
)

Creates an instance from json.

Implementation

factory Model.fromJson(Map<String, dynamic> json) {
  String id = "";
  if (json.containsKey(idKey)) {
    id = json[idKey].toString();
  }

  String userId = "";
  if (json.containsKey(userIdKey)) {
    userId = json[userIdKey].toString();
  }

  Map<String, dynamic> data = {};
  if (json.containsKey(dataKey)) {
    data = json[dataKey];
  }
  else {
    data = json;
  }

  return Model(id: id, userId: userId, data: data);
}