I am using google_maps_flutter in my flutter app to use google map I have custom marker icon and I load this with BitmapDescriptor.fromBytes(markerIcon) But I want to show icon from Url with some text. here is my flutter code:
Map<MarkerId, Marker> markers =
<MarkerId, Marker>{}; // CLASS MEMBER, MAP OF MARKS
void _add([center]) async {
for (int i = 0; i < sallersList.length; i++) {
if (sallersList[i]["uID"] != currentUser.uid) {
/*var request = await http.get(sallersList[i]["user_image"]);
var bytes = await request.bodyBytes;*/
final Uint8List markerIcon = await getBytesFromCanvas(150, 150);
var markerIdVal = sallersList[i]["uID"];
final MarkerId markerId = MarkerId(markerIdVal);
// creating a new MARKER
final Marker marker = Marker(
markerId: markerId,
position: LatLng(
sallersList[i]["latitude"], //+ sin(1 * pi / 6.0) / 20.0,
sallersList[i]["longitude"] //+ cos(1 * pi / 6.0) / 20.0,
),
// icon: BitmapDescriptor.fromBytes(bytes.buffer.asUint8List(),),
icon: BitmapDescriptor.fromBytes(markerIcon),
infoWindow: InfoWindow(
title: sallersList[i]["user_name"],
snippet: sallersList[i]["address"]),
onTap: () {
// print(sallersList[i]["uID"]);
Navigator.of(context).push(new MaterialPageRoute(
builder: (BuildContext context) =>
new DirectDetails()));
},
);
if (this.mounted)
setState(() {
// adding a new marker to map
markers[markerId] = marker;
});
}
}
}
Future<Uint8List> getBytesFromCanvas(int width, int height) async {
final ui.PictureRecorder pictureRecorder = ui.PictureRecorder();
final Canvas canvas = Canvas(pictureRecorder);
final Paint paint = Paint()..color = Colors.blue;
final Radius radius = Radius.circular(width/2);
canvas.drawRRect(
RRect.fromRectAndCorners(
Rect.fromLTWH(0.0, 0.0, width.toDouble(), height.toDouble()),
topLeft: radius,
topRight: radius,
bottomLeft: radius,
bottomRight: radius,
),
paint);
TextPainter painter = TextPainter(textDirection: TextDirection.ltr);
painter.text = TextSpan(
text: '1',
style: TextStyle(fontSize: 65.0, color: Colors.white),
);
painter.layout();
painter.paint(
canvas,
Offset((width * 0.5) - painter.width * 0.5,
(height * .5) - painter.height * 0.5));
final img = await pictureRecorder.endRecording().toImage(width, height);
final data = await img.toByteData(format: ui.ImageByteFormat.png);
return data.buffer.asUint8List();
}
This is what we want to achieve
This is what I am able to achieve.
Is it possible to achieve the same via flutter or any external image dependency that can create the images on the fly.