BitmapDescriptor.fromJson constructor

BitmapDescriptor.fromJson(
  1. Object json
)

The inverse of .toJson.

Implementation

// This is needed in Web to re-hydrate BitmapDescriptors that have been
// transformed to JSON for transport.
// TODO(https://github.com/flutter/flutter/issues/70330): Clean this up.
BitmapDescriptor.fromJson(Object json) : _json = json {
  assert(_json is List<dynamic>);
  final jsonList = json as List<dynamic>;
  assert(_validTypes.contains(jsonList[0]));
  switch (jsonList[0]) {
    case _defaultMarker:
      assert(jsonList.length <= 2);
      if (jsonList.length == 2) {
        assert(jsonList[1] is num);
        assert(0 <= jsonList[1] && jsonList[1] < 360);
      }
      break;
    case _fromBytes:
      assert(jsonList.length == 2);
      assert(jsonList[1] != null && jsonList[1] is List<int>);
      assert((jsonList[1] as List).isNotEmpty);
      break;
    case _fromAsset:
      assert(jsonList.length <= 3);
      assert(jsonList[1] != null && jsonList[1] is String);
      assert((jsonList[1] as String).isNotEmpty);
      if (jsonList.length == 3) {
        assert(jsonList[2] != null && jsonList[2] is String);
        assert((jsonList[2] as String).isNotEmpty);
      }
      break;
    case _fromAssetImage:
      assert(jsonList.length <= 4);
      assert(jsonList[1] != null && jsonList[1] is String);
      assert((jsonList[1] as String).isNotEmpty);
      assert(jsonList[2] != null && jsonList[2] is double);
      if (jsonList.length == 4) {
        assert(jsonList[3] != null && jsonList[3] is List);
        assert((jsonList[3] as List).length == 2);
      }
      break;
    default:
      break;
  }
}