Skip to content

Commit 14df02d

Browse files
author
=
committed
optimize rotate
1 parent f37846d commit 14df02d

9 files changed

+220
-49
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.4-stable
2+
3+
optimize rotate.
4+
15
# v1.4.3-stable
26

37
fix a pinned position bug.

README.md

Lines changed: 83 additions & 10 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.3-stable'
188+
ref: 'v1.4.4-stable'
189189
```
190190
191191
```yaml
192192
dependencies:
193-
flutter_constraintlayout: ^1.4.3-stable
193+
flutter_constraintlayout: ^1.4.4-stable
194194
```
195195
196196
```dart
@@ -925,15 +925,14 @@ class MarginExample extends StatelessWidget {
925925
```dart
926926
class PinnedPositionExampleState extends State<PinnedPositionExample> {
927927
late Timer timer;
928-
int angle = 0;
928+
double angle = 0;
929929
930930
@override
931931
void initState() {
932932
super.initState();
933933
timer = Timer.periodic(const Duration(milliseconds: 16), (_) {
934934
setState(() {
935935
angle++;
936-
angle %= 360;
937936
});
938937
});
939938
}
@@ -1035,15 +1034,16 @@ class PinnedPositionExampleState extends State<PinnedPositionExample> {
10351034
```dart
10361035
class TranslateExampleState extends State<TranslateExample> {
10371036
late Timer timer;
1038-
int angle = 0;
1037+
double angle = 0;
1038+
double earthRevolutionAngle = 0;
10391039
10401040
@override
10411041
void initState() {
10421042
super.initState();
10431043
timer = Timer.periodic(const Duration(milliseconds: 16), (_) {
10441044
setState(() {
1045-
angle++;
1046-
angle %= 360;
1045+
angle += 1;
1046+
earthRevolutionAngle += 0.1;
10471047
});
10481048
});
10491049
}
@@ -1064,12 +1064,85 @@ class TranslateExampleState extends State<TranslateExample> {
10641064
),
10651065
body: ConstraintLayout(
10661066
children: [
1067+
Container(
1068+
decoration: const BoxDecoration(
1069+
color: Colors.redAccent,
1070+
borderRadius: BorderRadius.all(Radius.circular(1000)),
1071+
),
1072+
child: const Text('----'),
1073+
alignment: Alignment.center,
1074+
).applyConstraint(
1075+
id: cId('sun'),
1076+
size: 200,
1077+
pinnedInfo: PinnedInfo(
1078+
parent,
1079+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1080+
Anchor(0.3, AnchorType.percent, 0.5, AnchorType.percent),
1081+
angle: earthRevolutionAngle * 365 / 25.4,
1082+
),
1083+
),
1084+
Container(
1085+
decoration: const BoxDecoration(
1086+
color: Colors.blue,
1087+
borderRadius: BorderRadius.all(Radius.circular(1000)),
1088+
),
1089+
child: const Text('----'),
1090+
alignment: Alignment.center,
1091+
).applyConstraint(
1092+
id: cId('earth'),
1093+
size: 100,
1094+
pinnedInfo: PinnedInfo(
1095+
cId('sun'),
1096+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1097+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1098+
angle: earthRevolutionAngle * 365,
1099+
),
1100+
translate: circleTranslate(
1101+
radius: 250,
1102+
angle: earthRevolutionAngle,
1103+
),
1104+
translateConstraint: true,
1105+
),
1106+
Container(
1107+
decoration: const BoxDecoration(
1108+
color: Colors.grey,
1109+
borderRadius: BorderRadius.all(Radius.circular(1000)),
1110+
),
1111+
child: const Text('----'),
1112+
alignment: Alignment.center,
1113+
).applyConstraint(
1114+
id: cId('moon'),
1115+
size: 50,
1116+
pinnedInfo: PinnedInfo(
1117+
cId('earth'),
1118+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1119+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1120+
angle: earthRevolutionAngle * 365 / 27.32,
1121+
),
1122+
translate: circleTranslate(
1123+
radius: 100,
1124+
angle: earthRevolutionAngle * 365 / 27.32,
1125+
),
1126+
translateConstraint: true,
1127+
),
1128+
Text('Sun rotates ${(earthRevolutionAngle * 365 / 25.4) ~/ 360} times')
1129+
.applyConstraint(
1130+
outTopCenterTo: cId('sun'),
1131+
),
1132+
Text('Earth rotates ${earthRevolutionAngle * 365 ~/ 360} times')
1133+
.applyConstraint(
1134+
outTopCenterTo: cId('earth'),
1135+
),
1136+
Text('Moon rotates ${(earthRevolutionAngle * 365 / 27.32) ~/ 360} times')
1137+
.applyConstraint(
1138+
outTopCenterTo: cId('moon'),
1139+
),
10671140
Container(
10681141
color: Colors.yellow,
10691142
).applyConstraint(
10701143
id: anchor,
1071-
size: 150,
1072-
centerTo: parent,
1144+
size: 250,
1145+
centerRightTo: parent.rightMargin(300),
10731146
),
10741147
Container(
10751148
color: Colors.red,
@@ -1256,7 +1329,7 @@ class BarrierExample extends StatelessWidget {
12561329

12571330
5. Every frame, ConstraintLayout compares the parameters and decides the following things:
12581331
1. Does the constraint need to be recalculated?
1259-
2. Does it need to be rearranged?
1332+
2. Does it need to be relayout?
12601333
3. Does it need to be redrawn?
12611334
4. Do you need to rearrange the drawing order?
12621335
5. Do you need to rearrange the order of event distribution?

README_CN.md

Lines changed: 82 additions & 9 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.3-stable'
162+
ref: 'v1.4.4-stable'
163163
```
164164
165165
```yaml
166166
dependencies:
167-
flutter_constraintlayout: ^1.4.3-stable
167+
flutter_constraintlayout: ^1.4.4-stable
168168
```
169169
170170
```dart
@@ -899,15 +899,14 @@ class MarginExample extends StatelessWidget {
899899
```dart
900900
class PinnedPositionExampleState extends State<PinnedPositionExample> {
901901
late Timer timer;
902-
int angle = 0;
902+
double angle = 0;
903903
904904
@override
905905
void initState() {
906906
super.initState();
907907
timer = Timer.periodic(const Duration(milliseconds: 16), (_) {
908908
setState(() {
909909
angle++;
910-
angle %= 360;
911910
});
912911
});
913912
}
@@ -1009,15 +1008,16 @@ class PinnedPositionExampleState extends State<PinnedPositionExample> {
10091008
```dart
10101009
class TranslateExampleState extends State<TranslateExample> {
10111010
late Timer timer;
1012-
int angle = 0;
1011+
double angle = 0;
1012+
double earthRevolutionAngle = 0;
10131013
10141014
@override
10151015
void initState() {
10161016
super.initState();
10171017
timer = Timer.periodic(const Duration(milliseconds: 16), (_) {
10181018
setState(() {
1019-
angle++;
1020-
angle %= 360;
1019+
angle += 1;
1020+
earthRevolutionAngle += 0.1;
10211021
});
10221022
});
10231023
}
@@ -1038,12 +1038,85 @@ class TranslateExampleState extends State<TranslateExample> {
10381038
),
10391039
body: ConstraintLayout(
10401040
children: [
1041+
Container(
1042+
decoration: const BoxDecoration(
1043+
color: Colors.redAccent,
1044+
borderRadius: BorderRadius.all(Radius.circular(1000)),
1045+
),
1046+
child: const Text('----'),
1047+
alignment: Alignment.center,
1048+
).applyConstraint(
1049+
id: cId('sun'),
1050+
size: 200,
1051+
pinnedInfo: PinnedInfo(
1052+
parent,
1053+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1054+
Anchor(0.3, AnchorType.percent, 0.5, AnchorType.percent),
1055+
angle: earthRevolutionAngle * 365 / 25.4,
1056+
),
1057+
),
1058+
Container(
1059+
decoration: const BoxDecoration(
1060+
color: Colors.blue,
1061+
borderRadius: BorderRadius.all(Radius.circular(1000)),
1062+
),
1063+
child: const Text('----'),
1064+
alignment: Alignment.center,
1065+
).applyConstraint(
1066+
id: cId('earth'),
1067+
size: 100,
1068+
pinnedInfo: PinnedInfo(
1069+
cId('sun'),
1070+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1071+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1072+
angle: earthRevolutionAngle * 365,
1073+
),
1074+
translate: circleTranslate(
1075+
radius: 250,
1076+
angle: earthRevolutionAngle,
1077+
),
1078+
translateConstraint: true,
1079+
),
1080+
Container(
1081+
decoration: const BoxDecoration(
1082+
color: Colors.grey,
1083+
borderRadius: BorderRadius.all(Radius.circular(1000)),
1084+
),
1085+
child: const Text('----'),
1086+
alignment: Alignment.center,
1087+
).applyConstraint(
1088+
id: cId('moon'),
1089+
size: 50,
1090+
pinnedInfo: PinnedInfo(
1091+
cId('earth'),
1092+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1093+
Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1094+
angle: earthRevolutionAngle * 365 / 27.32,
1095+
),
1096+
translate: circleTranslate(
1097+
radius: 100,
1098+
angle: earthRevolutionAngle * 365 / 27.32,
1099+
),
1100+
translateConstraint: true,
1101+
),
1102+
Text('Sun rotates ${(earthRevolutionAngle * 365 / 25.4) ~/ 360} times')
1103+
.applyConstraint(
1104+
outTopCenterTo: cId('sun'),
1105+
),
1106+
Text('Earth rotates ${earthRevolutionAngle * 365 ~/ 360} times')
1107+
.applyConstraint(
1108+
outTopCenterTo: cId('earth'),
1109+
),
1110+
Text('Moon rotates ${(earthRevolutionAngle * 365 / 27.32) ~/ 360} times')
1111+
.applyConstraint(
1112+
outTopCenterTo: cId('moon'),
1113+
),
10411114
Container(
10421115
color: Colors.yellow,
10431116
).applyConstraint(
10441117
id: anchor,
1045-
size: 150,
1046-
centerTo: parent,
1118+
size: 250,
1119+
centerRightTo: parent.rightMargin(300),
10471120
),
10481121
Container(
10491122
color: Colors.red,

example/pinned_position.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ class PinnedPositionExample extends StatefulWidget {
1414

1515
class PinnedPositionExampleState extends State<PinnedPositionExample> {
1616
late Timer timer;
17-
int angle = 0;
17+
double angle = 0;
1818

1919
@override
2020
void initState() {
2121
super.initState();
2222
timer = Timer.periodic(const Duration(milliseconds: 16), (_) {
2323
setState(() {
2424
angle++;
25-
angle %= 360;
2625
});
2726
});
2827
}

0 commit comments

Comments
 (0)