LocationDataModel.fromJson constructor

LocationDataModel.fromJson(
  1. Map<String, dynamic> data
)

Implementation

LocationDataModel.fromJson(Map<String, dynamic> data) {
  if (data['locationSharingFor'] == null ||
      data['lastUpdatedAt'] == null ||
      data['sender'] == null ||
      data['receiver'] == null) {
    assert(true, 'values can not be null');
  }

  Map<String, LocationSharingFor> tempLocationSharingFor = {};
  var locSharingMap = jsonDecode(data['locationSharingFor']);

  locSharingMap.forEach((key, value) {
    var locationData = LocationSharingFor.fromJson(value);
    tempLocationSharingFor[key] = locationData;
  });

  lat = data['lat'] != null && data['lat'] != 'null'
      ? double.parse(data['lat'])
      : null;
  long = data['long'] != null && data['long'] != 'null'
      ? double.parse(data['long'])
      : null;
  lastUpdatedAt = DateTime.parse(data['lastUpdatedAt']).toLocal();
  sender = data['sender'];
  receiver = data['receiver'];
  locationSharingFor = {...tempLocationSharingFor};
}