Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dottedSpacingFactor to customize dotted polyline spacing #1845

Merged
merged 6 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions example/lib/pages/polyline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ class _PolylinePageState extends State<PolylinePage> {
subtitle: 'Solid translucent color fill, with different color outline',
),
),
Polyline(
points: const [
LatLng(43.864797, 11.7112939),
LatLng(36.7948545, 10.2256785),
LatLng(35.566530, 5.584283),
],
strokeWidth: 10,
color: Colors.blueAccent,
isDotted: true,
segmentSpacingFactor: 3,
borderStrokeWidth: 8,
borderColor: Colors.blue.withOpacity(0.5),
hitValue: (
title: 'Blue Dotted Line with Custom Spacing',
subtitle:
'Dotted line with segment spacing controlled by `segmentSpacingFactor`',
),
),
];
late final _polylines =
Map.fromEntries(_polylinesRaw.map((e) => MapEntry(e.hitValue, e)));
Expand Down
2 changes: 1 addition & 1 deletion lib/src/layer/polyline_layer/painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class _PolylinePainter<R extends Object> extends CustomPainter {
final borderRadius = (borderPaint?.strokeWidth ?? 0) / 2;

if (isDotted) {
final spacing = strokeWidth * 1.5;
final spacing = strokeWidth * polyline.segmentSpacingFactor;
if (borderPaint != null && filterPaint != null) {
_paintDottedLine(borderPath, offsets, borderRadius, spacing);
_paintDottedLine(filterPath, offsets, radius, spacing);
Expand Down
12 changes: 12 additions & 0 deletions lib/src/layer/polyline_layer/polyline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ class Polyline<R extends Object> {
/// The width of the stroke
final double strokeWidth;

/// The multiplier used to calculate the spacing between segments in a dotted/
/// dashed polyline
///
/// A value of 1.0 will result in spacing equal to the `strokeWidth`.
/// Increasing the value increases the spacing with respect to `strokeWidth`.
///
/// Defaults to 1.5.
final double segmentSpacingFactor;

/// The color of the line stroke.
final Color color;

Expand Down Expand Up @@ -58,6 +67,7 @@ class Polyline<R extends Object> {
this.strokeJoin = StrokeJoin.round,
this.useStrokeWidthInMeter = false,
this.hitValue,
this.segmentSpacingFactor = 1.5,
});

@override
Expand All @@ -69,6 +79,7 @@ class Polyline<R extends Object> {
borderStrokeWidth == other.borderStrokeWidth &&
borderColor == other.borderColor &&
isDotted == other.isDotted &&
segmentSpacingFactor == other.segmentSpacingFactor &&
strokeCap == other.strokeCap &&
strokeJoin == other.strokeJoin &&
useStrokeWidthInMeter == other.useStrokeWidthInMeter &&
Expand All @@ -90,6 +101,7 @@ class Polyline<R extends Object> {
gradientColors,
colorsStop,
isDotted,
segmentSpacingFactor,
strokeCap,
strokeJoin,
useStrokeWidthInMeter,
Expand Down
Loading