calculateOpacity function
Calculates the opacity for markers based on their horizontal positions.
This function determines how transparent a marker should be based on its position relative to another marker (typically an exit point). It's used to create a visual fade effect for markers as they approach an exit point.
The opacity is calculated based on the horizontal distance between the 'from' position and the 'exitTo' position. If the distance is less than 10 logical pixels, the opacity starts decreasing. The opacity reaches 0 when the distance is 10 pixels or less, and reaches 1 when the distance is 16 pixels or more.
If no exit position is provided (exitTo is null), the opacity is set to 1 (fully opaque).
@param from The horizontal position (x-coordinate) of the marker. @param exitTo The horizontal position (x-coordinate) of the exit point, or null if there is no exit point. @return The calculated opacity value between 0 (transparent) and 1 (opaque).
Implementation
double calculateOpacity(double from, double? exitTo) {
if (exitTo != null) {
return min(max(exitTo - from - 10, 0) / 6, 1);
}
return 1;
}