Skip to content

Commit f002bfa

Browse files
committed
enhance rid
1 parent c1e44ce commit f002bfa

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/src/core.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ class ConstraintId {
388388
/// A relative id type that refers to a child element by its index
389389
class IndexConstraintId extends ConstraintId {
390390
/// [0, childCount-1]
391+
/// -1 represents the last element
392+
/// -2 represents the second to last element, and so on
391393
final int _siblingIndex;
392394

393395
IndexConstraintId(this._siblingIndex)
@@ -2151,6 +2153,10 @@ class _ConstraintRenderBox extends RenderBox
21512153
if (id is RelativeConstraintId) {
21522154
int targetIndex = childIndex! + id._siblingIndexOffset;
21532155
id = IndexConstraintId(targetIndex);
2156+
} else if (id is IndexConstraintId) {
2157+
if (id._siblingIndex < 0) {
2158+
id = IndexConstraintId(childCount + id._siblingIndex);
2159+
}
21542160
}
21552161

21562162
ConstrainedNode? node;

lib/src/extensions.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ ConstraintId cId(String id) {
99
}
1010

1111
ConstraintId rId(int childIndex) {
12-
assert(childIndex >= 0);
1312
return IndexConstraintId(childIndex);
1413
}
1514

0 commit comments

Comments
 (0)