flutterdartbitmappaintuint8array

Round Image File


I did this code to get an image from firestore and use it as an icon for a Map Marker.

final StorageReference storageReference =
FirebaseStorage().ref().child("ProfilePictures/" + widget.userId);
String avatarDownloadPath = await storageReference.getDownloadURL();
final File _avatar = await DefaultCacheManager().getSingleFile(avatarDownloadPath);
Uint8List __avatar = await _avatar.readAsBytes();
BitmapDescriptor avatar = BitmapDescriptor.fromBytes(__avatar);

setState(() {
  _markers.add(Marker(markerId: MarkerId("UserPosition"), position: userLocation, icon: avatar ));
});

This code works but I want to set the image a round shape and I don't know how to do this...


Solution

  • You can use use Canvas to draw a round image and use PictureRecorder to save as a final image and put it in the marker bitmapdescriptor, fyi: custom marker

    Replace TextPainter with ImagePainter in the article

    OR

    Follow this article by using widget, custom marker