Skip to content
Open
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
2 changes: 1 addition & 1 deletion lib/src/extensions/path_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension DashedPath on Path {
/// For example, the array `[5, 10]` would result in dashes 5 pixels long
/// followed by blank spaces 10 pixels long.
Path toDashedPath(List<int>? dashArray) {
if (dashArray != null) {
if (dashArray != null && dashArray.isNotEmpty) {
final castedArray = dashArray.map((value) => value.toDouble()).toList();
final dashedPath =
dashPath(this, dashArray: CircularIntervalList<double>(castedArray));
Expand Down
12 changes: 12 additions & 0 deletions test/extensions/path_extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ void main() {

expect(HelperMethods.equalsPaths(path1.toDashedPath([10, 5]), path2), true);
});

test('toDashedPath returns the original path for an empty dashArray', () {
// Regression test: previously, passing an empty list reached
// `CircularIntervalList<double>([]).next` inside `dashPath()` and threw
// `RangeError` for any non-empty source path. An empty `dashArray` has no
// dashes to repeat, so the source path is returned unchanged — mirroring
// the existing `null` behaviour.
final path = Path()
..moveTo(0, 0)
..lineTo(10, 0);
expect(path.toDashedPath([]), path);
});
}
Loading