Skip to content

Commit f37846d

Browse files
committed
fix a pinned position bug
1 parent b612157 commit f37846d

File tree

7 files changed

+79
-8
lines changed

7 files changed

+79
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v1.4.3-stable
2+
3+
fix a pinned position bug.
4+
15
# v1.4.2-stable
26

37
fix a rotate bug.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ dependencies:
185185
flutter_constraintlayout:
186186
git:
187187
url: 'https://github.com/hackware1993/Flutter-ConstraintLayout.git'
188-
ref: 'v1.4.2-stable'
188+
ref: 'v1.4.3-stable'
189189
```
190190
191191
```yaml
192192
dependencies:
193-
flutter_constraintlayout: ^1.4.2-stable
193+
flutter_constraintlayout: ^1.4.3-stable
194194
```
195195
196196
```dart

README_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ dependencies:
159159
flutter_constraintlayout:
160160
git:
161161
url: 'https://github.com/hackware1993/Flutter-ConstraintLayout.git'
162-
ref: 'v1.4.2-stable'
162+
ref: 'v1.4.3-stable'
163163
```
164164
165165
```yaml
166166
dependencies:
167-
flutter_constraintlayout: ^1.4.2-stable
167+
flutter_constraintlayout: ^1.4.3-stable
168168
```
169169
170170
```dart

example/translate.dart

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ class TranslateExample extends StatefulWidget {
1515
class TranslateExampleState extends State<TranslateExample> {
1616
late Timer timer;
1717
int angle = 0;
18+
int earthAngle = 0;
1819

1920
@override
2021
void initState() {
2122
super.initState();
2223
timer = Timer.periodic(const Duration(milliseconds: 16), (_) {
2324
setState(() {
24-
angle++;
25+
angle += 5;
2526
angle %= 360;
27+
earthAngle += 1;
28+
earthAngle %= 360;
2629
});
2730
});
2831
}
@@ -43,12 +46,68 @@ class TranslateExampleState extends State<TranslateExample> {
4346
),
4447
body: ConstraintLayout(
4548
children: [
49+
Container(
50+
decoration: const BoxDecoration(
51+
color: Colors.redAccent,
52+
borderRadius: BorderRadius.all(Radius.circular(1000)),
53+
),
54+
child: const Text('Sun'),
55+
alignment: Alignment.center,
56+
).applyConstraint(
57+
size: 200,
58+
pinnedInfo: PinnedInfo(
59+
parent,
60+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
61+
Anchor(0.3, AnchorType.percent, 0.5, AnchorType.percent),
62+
),
63+
),
64+
Container(
65+
decoration: const BoxDecoration(
66+
color: Colors.blue,
67+
borderRadius: BorderRadius.all(Radius.circular(1000)),
68+
),
69+
child: const Text('Earth'),
70+
alignment: Alignment.center,
71+
).applyConstraint(
72+
size: 100,
73+
pinnedInfo: PinnedInfo(
74+
sId(-1),
75+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
76+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
77+
angle: earthAngle,
78+
),
79+
translate: circleTranslate(
80+
radius: 350,
81+
angle: earthAngle,
82+
),
83+
translateConstraint: true,
84+
),
85+
Container(
86+
decoration: const BoxDecoration(
87+
color: Colors.grey,
88+
borderRadius: BorderRadius.all(Radius.circular(1000)),
89+
),
90+
child: const Text('Moon'),
91+
alignment: Alignment.center,
92+
).applyConstraint(
93+
size: 50,
94+
pinnedInfo: PinnedInfo(
95+
sId(-1),
96+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
97+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
98+
angle: angle,
99+
),
100+
translate: circleTranslate(
101+
radius: 100,
102+
angle: angle,
103+
),
104+
),
46105
Container(
47106
color: Colors.yellow,
48107
).applyConstraint(
49108
id: anchor,
50109
size: 150,
51-
centerTo: parent,
110+
centerRightTo: parent.rightMargin(300),
52111
),
53112
Container(
54113
color: Colors.red,

lib/src/core.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,11 @@ class _ConstraintRenderBox extends RenderBox
28982898
node.pinnedConstraint!.getX() + targetOffset.dx - selfOffset.dx;
28992899
double offsetY =
29002900
node.pinnedConstraint!.getY() + targetOffset.dy - selfOffset.dy;
2901-
return Offset(offsetX, offsetY);
2901+
Offset offset = Offset(offsetX, offsetY);
2902+
if (node.pinnedInfo != null && node.translateConstraint) {
2903+
offset += node.translate;
2904+
}
2905+
return offset;
29022906
}
29032907
}
29042908

lib/src/utils.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ void debugCheckConstraintsIntegrity(List<ConstrainedNode> nodeList) {
158158
throw ConstraintLayoutException(
159159
'When setting pinnedInfo, targetAnchor can not be null.');
160160
}
161+
if (element.translate is PinnedTranslate) {
162+
throw ConstraintLayoutException(
163+
'When setting pinnedInfo, pinned translate can not be set.');
164+
}
161165
continue;
162166
}
163167

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_constraintlayout
22
description: A super powerful Stack, build flexible layouts with constraints. Similar to ConstraintLayout for Android and AutoLayout for iOS.
3-
version: 1.4.2-stable
3+
version: 1.4.3-stable
44
anthor: hackware
55
homepage: https://github.com/hackware1993/Flutter-ConstraintLayout
66

0 commit comments

Comments
 (0)