Skip to content

Instantly share code, notes, and snippets.

@moho12n
Created June 14, 2020 20:46
Show Gist options
  • Save moho12n/6f37c7868215890a040daa00b2739004 to your computer and use it in GitHub Desktop.
Save moho12n/6f37c7868215890a040daa00b2739004 to your computer and use it in GitHub Desktop.
//******* getMarkers */
Future<Uint8List> getBytesFromAsset(String path, int width) async {
ByteData data = await rootBundle.load(path);
ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(),
targetWidth: width);
ui.FrameInfo fi = await codec.getNextFrame();
return (await fi.image.toByteData(format: ui.ImageByteFormat.png))
.buffer
.asUint8List();
}
void getMarkers() async {
final Uint8List userMarkerIcon =
await getBytesFromAsset('assets/normalMarker.png', 75);
final Uint8List selectedMarkerIcon =
await getBytesFromAsset('assets/selectedMarker.png', 100);
markers = {};
Tools.markersList.forEach((element) {
if (element.latitude != null && element.longitude != null) {
if (element.id == indexMarker) {
markers.add(Marker(
draggable: false,
markerId: MarkerId(element.latitude + element.longitude),
position: LatLng(
double.tryParse(element.latitude),
double.tryParse(element.longitude),
),
icon: BitmapDescriptor.fromBytes(selectedMarkerIcon),
infoWindow: InfoWindow(title: element.name)));
} else {
markers.add(Marker(
draggable: false,
markerId: MarkerId(element.latitude + element.longitude),
position: LatLng(
double.tryParse(element.latitude),
double.tryParse(element.longitude),
),
icon: BitmapDescriptor.fromBytes(userMarkerIcon),
infoWindow: InfoWindow(title: element.name)));
}
}
});
valueNotifier.value = indexMarker; // we will need it soon
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment