Skip to content

Instantly share code, notes, and snippets.

@jjvillavicencio
Created April 14, 2020 19:51
Show Gist options
  • Save jjvillavicencio/391f6b613e672bb6eed53a62afad9cc8 to your computer and use it in GitHub Desktop.
Save jjvillavicencio/391f6b613e672bb6eed53a62afad9cc8 to your computer and use it in GitHub Desktop.
Flutter GoogleMaps custom marker with network image
final int targetWidth = 120;
final File markerImageFile = await DefaultCacheManager()
.getSingleFile("${Enviroment.server}$avatar");
final Uint8List markerImageBytes = await markerImageFile.readAsBytes();
final Codec markerImageCodec = await instantiateImageCodec(
markerImageBytes,
targetWidth: targetWidth,
);
final FrameInfo frameInfo = await markerImageCodec.getNextFrame();
final ByteData byteData = await frameInfo.image.toByteData(
format: ImageByteFormat.png,
);
final Uint8List resizedMarkerImageBytes = byteData.buffer.asUint8List();
BitmapDescriptor customPinMarker =
_createCustomMarkers(context, resizedMarkerImageBytes);
BitmapDescriptor _createCustomMarkers(
BuildContext context, Uint8List markerImageBytes) {
return BitmapDescriptor.fromBytes(markerImageBytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment