Created
April 14, 2020 19:51
Flutter GoogleMaps custom marker with network image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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