Skip to content

Commit 4ffddf2

Browse files
committed
fix a margin bug
1 parent c7cc04a commit 4ffddf2

File tree

2 files changed

+51
-29
lines changed

2 files changed

+51
-29
lines changed

example/margin.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ class MarginExample extends StatelessWidget {
3838
size: 50,
3939
topRightTo: parent.rightMargin(20).topMargin(50),
4040
),
41+
Container(
42+
color: Colors.pink,
43+
).applyConstraint(
44+
size: 50,
45+
outBottomCenterTo: sId(-2).topMargin(20),
46+
),
4147
],
4248
),
4349
);

lib/src/constraint_layout.dart

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -782,26 +782,42 @@ class ConstraintId {
782782
contextCacheNode = node;
783783
}
784784

785-
late _Align left = _Align(this, _AlignType.left)
785+
late final _Align left = _Align(this, _AlignType.left)
786786
.._margin = _leftMargin
787787
.._goneMargin = _leftGoneMargin;
788788

789-
late _Align top = _Align(this, _AlignType.top)
789+
late final _Align top = _Align(this, _AlignType.top)
790790
.._margin = _topMargin
791791
.._goneMargin = _topGoneMargin;
792792

793-
late _Align right = _Align(this, _AlignType.right)
793+
late final _Align right = _Align(this, _AlignType.right)
794794
.._margin = _rightMargin
795795
.._goneMargin = _rightGoneMargin;
796796

797-
late _Align bottom = _Align(this, _AlignType.bottom)
797+
late final _Align bottom = _Align(this, _AlignType.bottom)
798798
.._margin = _bottomMargin
799799
.._goneMargin = _bottomGoneMargin;
800800

801-
late _Align baseline = _Align(this, _AlignType.baseline)
801+
late final _Align baseline = _Align(this, _AlignType.baseline)
802802
.._margin = _bottomMargin
803803
.._goneMargin = _bottomGoneMargin;
804804

805+
late final _Align _leftReverse = _Align(this, _AlignType.left)
806+
.._margin = _rightMargin
807+
.._goneMargin = _rightGoneMargin;
808+
809+
late final _Align _topReverse = _Align(this, _AlignType.top)
810+
.._margin = _bottomMargin
811+
.._goneMargin = _bottomGoneMargin;
812+
813+
late final _Align _rightReverse = _Align(this, _AlignType.right)
814+
.._margin = _leftMargin
815+
.._goneMargin = _leftGoneMargin;
816+
817+
late final _Align _bottomReverse = _Align(this, _AlignType.bottom)
818+
.._margin = _topMargin
819+
.._goneMargin = _topGoneMargin;
820+
805821
@override
806822
bool operator ==(Object other) {
807823
if (identical(this, other)) {
@@ -1388,102 +1404,102 @@ class Constraint extends ConstraintDefine {
13881404
}
13891405

13901406
if (outTopLeftTo != null) {
1391-
right = outTopLeftTo!.left;
1392-
bottom = outTopLeftTo!.top;
1407+
right = outTopLeftTo!._leftReverse;
1408+
bottom = outTopLeftTo!._topReverse;
13931409
}
13941410

13951411
if (outTopCenterTo != null) {
13961412
left = outTopCenterTo!.left;
13971413
right = outTopCenterTo!.right;
1398-
bottom = outTopCenterTo!.top;
1414+
bottom = outTopCenterTo!._topReverse;
13991415
}
14001416

14011417
if (outTopRightTo != null) {
1402-
left = outTopRightTo!.right;
1403-
bottom = outTopRightTo!.top;
1418+
left = outTopRightTo!._rightReverse;
1419+
bottom = outTopRightTo!._topReverse;
14041420
}
14051421

14061422
if (outCenterLeftTo != null) {
14071423
top = outCenterLeftTo!.top;
14081424
bottom = outCenterLeftTo!.bottom;
1409-
right = outCenterLeftTo!.left;
1425+
right = outCenterLeftTo!._leftReverse;
14101426
}
14111427

14121428
if (outCenterRightTo != null) {
14131429
top = outCenterRightTo!.top;
14141430
bottom = outCenterRightTo!.bottom;
1415-
left = outCenterRightTo!.right;
1431+
left = outCenterRightTo!._rightReverse;
14161432
}
14171433

14181434
if (outBottomLeftTo != null) {
1419-
right = outBottomLeftTo!.left;
1420-
top = outBottomLeftTo!.bottom;
1435+
right = outBottomLeftTo!._leftReverse;
1436+
top = outBottomLeftTo!._bottomReverse;
14211437
}
14221438

14231439
if (outBottomCenterTo != null) {
14241440
left = outBottomCenterTo!.left;
14251441
right = outBottomCenterTo!.right;
1426-
top = outBottomCenterTo!.bottom;
1442+
top = outBottomCenterTo!._bottomReverse;
14271443
}
14281444

14291445
if (outBottomRightTo != null) {
1430-
left = outBottomRightTo!.right;
1431-
top = outBottomRightTo!.bottom;
1446+
left = outBottomRightTo!._rightReverse;
1447+
top = outBottomRightTo!._bottomReverse;
14321448
}
14331449

14341450
if (centerTopLeftTo != null) {
14351451
left = centerTopLeftTo!.left;
1436-
right = centerTopLeftTo!.left;
1452+
right = centerTopLeftTo!._leftReverse;
14371453
top = centerTopLeftTo!.top;
1438-
bottom = centerTopLeftTo!.top;
1454+
bottom = centerTopLeftTo!._topReverse;
14391455
}
14401456

14411457
if (centerTopCenterTo != null) {
14421458
left = centerTopCenterTo!.left;
14431459
right = centerTopCenterTo!.right;
14441460
top = centerTopCenterTo!.top;
1445-
bottom = centerTopCenterTo!.top;
1461+
bottom = centerTopCenterTo!._topReverse;
14461462
}
14471463

14481464
if (centerTopRightTo != null) {
1449-
left = centerTopRightTo!.right;
1465+
left = centerTopRightTo!._rightReverse;
14501466
right = centerTopRightTo!.right;
14511467
top = centerTopRightTo!.top;
1452-
bottom = centerTopRightTo!.top;
1468+
bottom = centerTopRightTo!._topReverse;
14531469
}
14541470

14551471
if (centerCenterLeftTo != null) {
14561472
left = centerCenterLeftTo!.left;
1457-
right = centerCenterLeftTo!.left;
1473+
right = centerCenterLeftTo!._leftReverse;
14581474
top = centerCenterLeftTo!.top;
14591475
bottom = centerCenterLeftTo!.bottom;
14601476
}
14611477

14621478
if (centerCenterRightTo != null) {
1463-
left = centerCenterRightTo!.right;
1479+
left = centerCenterRightTo!._rightReverse;
14641480
right = centerCenterRightTo!.right;
14651481
top = centerCenterRightTo!.top;
14661482
bottom = centerCenterRightTo!.bottom;
14671483
}
14681484

14691485
if (centerBottomLeftTo != null) {
14701486
left = centerBottomLeftTo!.left;
1471-
right = centerBottomLeftTo!.left;
1472-
top = centerBottomLeftTo!.bottom;
1487+
right = centerBottomLeftTo!._leftReverse;
1488+
top = centerBottomLeftTo!._bottomReverse;
14731489
bottom = centerBottomLeftTo!.bottom;
14741490
}
14751491

14761492
if (centerBottomCenterTo != null) {
14771493
left = centerBottomCenterTo!.left;
14781494
right = centerBottomCenterTo!.right;
1479-
top = centerBottomCenterTo!.bottom;
1495+
top = centerBottomCenterTo!._bottomReverse;
14801496
bottom = centerBottomCenterTo!.bottom;
14811497
}
14821498

14831499
if (centerBottomRightTo != null) {
1484-
left = centerBottomRightTo!.right;
1500+
left = centerBottomRightTo!._rightReverse;
14851501
right = centerBottomRightTo!.right;
1486-
top = centerBottomRightTo!.bottom;
1502+
top = centerBottomRightTo!._bottomReverse;
14871503
bottom = centerBottomRightTo!.bottom;
14881504
}
14891505

0 commit comments

Comments
 (0)