toMap method Null safety

Map<String, dynamic> toMap()

Implementation

Map<String, dynamic> toMap() {
  final Map<String, dynamic> optionsMap = <String, dynamic>{};

  void addIfNonNull(String fieldName, dynamic value) {
    if (value != null) {
      optionsMap[fieldName] = value;
    }
  }

  void addMapIfNonNull(String fieldName, Uint8List value) {
    if (value != null) {
      optionsMap[fieldName] = <String, dynamic>{
        'image': value,
        'length': value.length
      };
    }
  }

  addIfNonNull('includeDeviceLocationButton',
      includeDeviceLocationButton); //Android Only
  addIfNonNull('includeSearch', includeSearch);
  addIfNonNull('mapMaxZoom', mapMaxZoom);
  addIfNonNull('mapMinZoom', mapMinZoom);
  addIfNonNull('searchPlaceOption', placeOptions?.toMap());
  addIfNonNull('toolbarColor', toolbarColor);
  addIfNonNull('statingCameraPosition', statingCameraPosition?.toMap());
  addIfNonNull('startingBounds', startingBounds?.toList());
  if (marker != null) {
    addMapIfNonNull('marker', marker!);
  }
  addIfNonNull('toolbarTintColor', toolbarTintColor); //Android Only
  addIfNonNull("placeNameLabelTextColor", placeNameLabelTextColor);
  addIfNonNull("pickerButtonTitleColor", pickerButtonTitleColor);
  addIfNonNull("pickerButtonTitle", pickerButtonTitle);
  addIfNonNull("pickerButtonBackgroundColor", pickerButtonBackgroundColor);

  //new
  addIfNonNull('addressTextColor', addressTextColor);
  addIfNonNull('showMarkerShadow', showMarkerShadow);

  // ios
  addIfNonNull(
      "infoBottomViewBackgroundColor", infoBottomViewBackgroundColor);
  if (searchButtonImage != null) {
    addMapIfNonNull('searchButtonImage', searchButtonImage!);
  }

  return optionsMap;
}