decode static method Null safety

HillshadeLayer decode(
  1. String properties
)

Implementation

static HillshadeLayer decode(String properties) {
  var map = json.decode(properties);
  if (map["layout"] == null) {
    map["layout"] = {};
  }
  if (map["paint"] == null) {
    map["paint"] = {};
  }
  return HillshadeLayer(
    id: map["id"],
    sourceId: map["source"],
    sourceLayer: map["source-layer"],
    minZoom: map["minzoom"]?.toDouble(),
    maxZoom: map["maxzoom"]?.toDouble(),
    visibility: map["layout"]["visibility"] == null
        ? Visibility.VISIBLE
        : Visibility.values.firstWhere((e) => e
            .toString()
            .split('.')
            .last
            .toLowerCase()
            .contains(map["layout"]["visibility"])),
    hillshadeAccentColor:
        (map["paint"]["hillshade-accent-color"] as List?)?.toRGBAInt(),
    hillshadeExaggeration: map["paint"]["hillshade-exaggeration"] is num?
        ? (map["paint"]["hillshade-exaggeration"] as num?)?.toDouble()
        : null,
    hillshadeHighlightColor:
        (map["paint"]["hillshade-highlight-color"] as List?)?.toRGBAInt(),
    hillshadeIlluminationAnchor:
        map["paint"]["hillshade-illumination-anchor"] == null
            ? null
            : HillshadeIlluminationAnchor.values.firstWhere((e) => e
                .toString()
                .split('.')
                .last
                .toLowerCase()
                .contains(map["paint"]["hillshade-illumination-anchor"])),
    hillshadeIlluminationDirection:
        map["paint"]["hillshade-illumination-direction"] is num?
            ? (map["paint"]["hillshade-illumination-direction"] as num?)
                ?.toDouble()
            : null,
    hillshadeShadowColor:
        (map["paint"]["hillshade-shadow-color"] as List?)?.toRGBAInt(),
  );
}