Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[google_maps_flutter_platform_interface] Convert BitmapDescriptor to typesafe subclasses #7699

Merged
merged 15 commits into from
Oct 4, 2024
Prev Previous commit
Next Next commit
Convert BytesBitmap
  • Loading branch information
yaakovschectman committed Oct 4, 2024
commit 17053063583041cf035a9bbe4121ff03b492034d
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ class BitmapDescriptor {
assert(0 <= secondElement && secondElement < 360);
return DefaultMarker(secondElement);
}
return DefaultMarker();
return const DefaultMarker();
case _fromBytes:
assert(jsonList.length == 2);
assert(jsonList[1] != null && jsonList[1] is List<int>);
assert((jsonList[1] as List<int>).isNotEmpty);
return BytesBitmap(byteData: jsonList[1] as Uint8List);
case _fromAsset:
assert(jsonList.length <= 3);
assert(jsonList[1] != null && jsonList[1] is String);
Expand Down Expand Up @@ -225,15 +226,7 @@ class BitmapDescriptor {
static BitmapDescriptor fromBytes(Uint8List byteData, {Size? size}) {
assert(byteData.isNotEmpty,
'Cannot create BitmapDescriptor with empty byteData');
return BitmapDescriptor._(<Object>[
_fromBytes,
byteData,
if (kIsWeb && size != null)
<Object>[
size.width,
size.height,
]
]);
return BytesBitmap(byteData: byteData, size: size);
}

/// Creates a [BitmapDescriptor] from an asset using [AssetMapBitmap].
Expand Down Expand Up @@ -326,6 +319,18 @@ class DefaultMarker extends BitmapDescriptor {
}
}

class BytesBitmap extends BitmapDescriptor {
const BytesBitmap({required this.byteData, this.size}) : super._(const <Object>[]);

final Uint8List byteData;
final Size? size;

@override
Object toJson() {
return <Object>[BitmapDescriptor._fromBytes, byteData, if (size != null && kIsWeb) <Object>[size!.width, size!.height]];
}
}

/// Represents a [BitmapDescriptor] base class for map bitmaps.
///
/// See [AssetMapBitmap] and [BytesMapBitmap] for concrete implementations.
Expand Down