@@ -6,6 +6,8 @@ A super powerful Stack, build flexible layouts with constraints. Similar to Cons
66Android and AutoLayout for iOS. But the code implementation is much more efficient, it has O(n)
77layout time complexity and no linear equation solving is required.
88
9+ ** It is a layout and a more modern general layout framework.**
10+
911# Greatly improve Flutter development experience and efficiency. Improve application performance
1012
1113No matter how complex the layout is and how deep the constraints are, it has almost the same
@@ -97,7 +99,7 @@ two-way constraints, such as chains(not yet supported, please use with Flex).
97996 . bias(when there are constraints left and right or top and bottom, horizontalBias and verticalBias
98100 can be used to adjust the offset. The default value is 0.5, which means centering)
991017 . z-index(drawing order, default is child index)
100- 8 . translate
102+ 8 . translate、rotate
1011039 . percentage layout(when size is set to matchConstraint, the percentage layout will take effect,
102104 the default percentage is 1 (100%). The relevant properties are widthPercent, heightPercent,
103105 widthPercentageAnchor, heightPercentageAnchor)
@@ -183,12 +185,12 @@ dependencies:
183185 flutter_constraintlayout :
184186 git :
185187 url : ' https://github.com/hackware1993/Flutter-ConstraintLayout.git'
186- ref : ' v1.3 .0-stable'
188+ ref : ' v1.4 .0-stable'
187189` ` `
188190
189191` ` ` yaml
190192dependencies :
191- flutter_constraintlayout : ^1.3 .0-stable
193+ flutter_constraintlayout : ^1.4 .0-stable
192194` ` `
193195
194196` ` ` dart
@@ -1026,6 +1028,96 @@ class PinnedPositionExampleState extends State<PinnedPositionExample> {
10261028}
10271029```
10281030
1031+ 9 . translate [ Flutter Web Online Example] ( https://constraintlayout.flutterfirst.cn )
1032+
1033+ ![ translate.gif] ( https://github.com/hackware1993/flutter-constraintlayout/blob/master/translate.gif?raw=true )
1034+
1035+ ``` dart
1036+ class TranslateExampleState extends State<TranslateExample> {
1037+ late Timer timer;
1038+ int angle = 0;
1039+
1040+ @override
1041+ void initState() {
1042+ super.initState();
1043+ timer = Timer.periodic(const Duration(milliseconds: 16), (_) {
1044+ setState(() {
1045+ angle++;
1046+ angle %= 360;
1047+ });
1048+ });
1049+ }
1050+
1051+ @override
1052+ void dispose() {
1053+ super.dispose();
1054+ timer.cancel();
1055+ }
1056+
1057+ @override
1058+ Widget build(BuildContext context) {
1059+ ConstraintId anchor = ConstraintId('anchor');
1060+ return Scaffold(
1061+ appBar: const CustomAppBar(
1062+ title: 'Translate',
1063+ codePath: 'example/translate.dart',
1064+ ),
1065+ body: ConstraintLayout(
1066+ children: [
1067+ Container(
1068+ color: Colors.yellow,
1069+ ).applyConstraint(
1070+ id: anchor,
1071+ size: 150,
1072+ centerTo: parent,
1073+ ),
1074+ Container(
1075+ decoration: const BoxDecoration(
1076+ color: Colors.red,
1077+ ),
1078+ child: const Text('pinned translate'),
1079+ ).applyConstraint(
1080+ size: wrapContent,
1081+ centerTo: anchor,
1082+ translate: PinnedTranslate(
1083+ PinnedInfo(
1084+ null,
1085+ Anchor(0.5, AnchorType.percent, 0.5, AnchorType.percent),
1086+ null,
1087+ angle: angle,
1088+ ),
1089+ ),
1090+ ),
1091+ Container(
1092+ decoration: const BoxDecoration(
1093+ color: Colors.blue,
1094+ ),
1095+ child: const Text('circle translate'),
1096+ ).applyConstraint(
1097+ size: wrapContent,
1098+ centerTo: anchor,
1099+ translate: circleTranslate(
1100+ radius: 150,
1101+ angle: angle,
1102+ ),
1103+ ),
1104+ Container(
1105+ decoration: const BoxDecoration(
1106+ color: Colors.orange,
1107+ ),
1108+ child: const Text('normal translate'),
1109+ ).applyConstraint(
1110+ size: wrapContent,
1111+ outBottomCenterTo: anchor,
1112+ translate: Offset(0, angle / 5),
1113+ )
1114+ ],
1115+ ),
1116+ );
1117+ }
1118+ }
1119+ ```
1120+
10291121# Performance optimization
10301122
103111231 . When the layout is complex, if the child elements need to be repainted frequently, it is
@@ -1203,6 +1295,16 @@ class ConstraintVersionExampleState extends State<ConstraintVersionExample> {
12031295}
12041296```
12051297
1298+ # Extension
1299+
1300+ ConstraintLayout's constraint-based layout algorithm is extremely powerful and flexible, and it
1301+ seems that it can become a general layout framework. You just need to generate constraints and hand
1302+ over the task of layout to ConstraintLayout. Some built-in features like circle position, staggered
1303+ grid, grid, and list are available in extended form.
1304+
1305+ The charts in the online example is a typical extension. Extensions for ConstraintLayout are
1306+ welcome.
1307+
12061308# Support me
12071309
12081310If it helps you a lot, consider sponsoring me a cup of milk tea, or giving a star. Your support is
0 commit comments