I have a number of trips with each having a list of positions. I need assign a color for each trip but what's happening is that as the lines are being drawn, instead of changing the new color for each trip, it changes for all polylines already drawn. How can I do it for each trip?
getTrips() async {
await Future.forEach(trips, (element) async {
List positions = element['positions'] as List;
await Future.forEach(positions, (element) async {
latitude = element['coordinates'][0];
longitude = element['coordinates'][1];
direction = element['direction'] ?? 0;
//Current position
position = LatLng(latitude ?? 0, longitude ?? 0);
positionList.add(position);
addMarker();
});
});}
addMarker() async {
var m = markers.firstWhere((p) => p.markerId == MarkerId(equipmentId), orElse: () => null);
if (markers.isNotEmpty) {
markers.remove(m);
}
selectedMarker = MarkerId(equipmentId);
markers
..add(Marker(
visible: true,
markerId: selectedMarker,
position: position,
icon: customIcon,
anchor: Offset(0.5, 0.5),
rotation: direction,
));
_polyline.add(Polyline(
polylineId: PolylineId(_polylineIdCounter.toString()),
visible: true,
width: 6,
points: positionList,
color: tripColors[++colorIndex % tripColors.length],
));
_polylineIdCounter++;
cPosition = CameraPosition(
zoom: cameraZoom,
target: LatLng(position.latitude, position.longitude),
);
if (mounted) setState(() {});
_animateCamera(cPosition);
}