GeocodeData constructor Null safety

GeocodeData(
  1. String inputString,
  2. String featureNameHeader,
  3. String stateHeader,
  4. String latitudeHeader,
  5. String longitudeHeader,
  6. {int numMarkers = 1,
  7. String fieldDelimiter = defaultFieldDelimiter,
  8. String textDelimiter = defaultTextDelimiter,
  9. String eol = defaultEol}
)

Implementation

GeocodeData(this.inputString, this.featureNameHeader, this.stateHeader,
    this.latitudeHeader, this.longitudeHeader,
    {this.numMarkers = 1,
    this.fieldDelimiter = defaultFieldDelimiter,
    this.textDelimiter = defaultTextDelimiter,
    this.eol = defaultEol}) {
  var rowsAsListOfValues = const CsvToListConverter().convert(inputString,
      fieldDelimiter: fieldDelimiter,
      textDelimiter: textDelimiter,
      eol: eol,
      shouldParseNumbers: false);

  _featureNameHeaderSN =
      rowsAsListOfValues[0].indexWhere((x) => x == featureNameHeader);
  _stateHeaderSN = rowsAsListOfValues[0].indexWhere((x) => x == stateHeader);
  _latitudeHeaderSN =
      rowsAsListOfValues[0].indexWhere((x) => x == latitudeHeader);
  _longitudeHeaderSN =
      rowsAsListOfValues[0].indexWhere((x) => x == longitudeHeader);

  if (_featureNameHeaderSN == -1 ||
      _stateHeaderSN == -1 ||
      _latitudeHeaderSN == -1 ||
      _longitudeHeaderSN == -1) {
    throw Exception('Some of header is not find in file');
  }

  var locations = rowsAsListOfValues
      .sublist(1)
      .map((model) => LocationData(
          model[_featureNameHeaderSN],
          model[_stateHeaderSN],
          double.tryParse(model[_latitudeHeaderSN].toString()) ?? -1,
          double.tryParse(model[_longitudeHeaderSN].toString()) ?? -1))
      .map((model) => model.toJson())
      .toList();

  _kdTree = KDTree(locations, _distance, ['latitude', 'longitude']);
}