Skip to content

Commit ded8ec9

Browse files
committed
release v1.5.1-stable
1 parent 1477eea commit ded8ec9

11 files changed

+144
-40
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v1.5.1-stable
2+
3+
add paint callback support.
4+
15
# v1.5.0-stable
26

37
1. refactor debug function.

README.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ dependencies:
193193
flutter_constraintlayout:
194194
git:
195195
url: 'https://github.com/hackware1993/Flutter-ConstraintLayout.git'
196-
ref: 'v1.5.0-stable'
196+
ref: 'v1.5.1-stable'
197197
```
198198
199199
```yaml
200200
dependencies:
201-
flutter_constraintlayout: ^1.5.0-stable
201+
flutter_constraintlayout: ^1.5.1-stable
202202
```
203203
204204
```dart
@@ -1040,10 +1040,26 @@ class PinnedPositionExampleState extends State<PinnedPositionExample> {
10401040
![translate.gif](https://github.com/hackware1993/flutter-constraintlayout/blob/master/translate.gif?raw=true)
10411041

10421042
```dart
1043+
class TrackPainter extends CustomPainter {
1044+
Queue<Offset> points = Queue();
1045+
Paint painter = Paint();
1046+
1047+
TrackPainter(this.points);
1048+
1049+
@override
1050+
void paint(Canvas canvas, Size size) {
1051+
canvas.drawPoints(PointMode.polygon, points.toList(), painter);
1052+
}
1053+
1054+
@override
1055+
bool shouldRepaint(CustomPainter oldDelegate) => true;
1056+
}
1057+
10431058
class TranslateExampleState extends State<TranslateExample> {
10441059
late Timer timer;
10451060
double angle = 0;
10461061
double earthRevolutionAngle = 0;
1062+
Queue<Offset> points = Queue();
10471063
10481064
@override
10491065
void initState() {
@@ -1072,6 +1088,12 @@ class TranslateExampleState extends State<TranslateExample> {
10721088
),
10731089
body: ConstraintLayout(
10741090
children: [
1091+
CustomPaint(
1092+
painter: TrackPainter(points),
1093+
).applyConstraint(
1094+
width: matchParent,
1095+
height: matchParent,
1096+
),
10751097
Container(
10761098
decoration: const BoxDecoration(
10771099
color: Colors.redAccent,
@@ -1132,6 +1154,12 @@ class TranslateExampleState extends State<TranslateExample> {
11321154
angle: earthRevolutionAngle * 365 / 27.32,
11331155
),
11341156
translateConstraint: true,
1157+
paintCallback: (_, __, ____, offset, ______) {
1158+
points.add(offset!);
1159+
if (points.length > 2000) {
1160+
points.removeFirst();
1161+
}
1162+
},
11351163
),
11361164
Text('Sun rotates ${(earthRevolutionAngle * 365 / 25.4) ~/ 360} times')
11371165
.applyConstraint(

README_CN.md

+30-2
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ dependencies:
167167
flutter_constraintlayout:
168168
git:
169169
url: 'https://github.com/hackware1993/Flutter-ConstraintLayout.git'
170-
ref: 'v1.5.0-stable'
170+
ref: 'v1.5.1-stable'
171171
```
172172
173173
```yaml
174174
dependencies:
175-
flutter_constraintlayout: ^1.5.0-stable
175+
flutter_constraintlayout: ^1.5.1-stable
176176
```
177177
178178
```dart
@@ -1014,10 +1014,26 @@ class PinnedPositionExampleState extends State<PinnedPositionExample> {
10141014
![translate.gif](https://github.com/hackware1993/flutter-constraintlayout/blob/master/translate.gif?raw=true)
10151015

10161016
```dart
1017+
class TrackPainter extends CustomPainter {
1018+
Queue<Offset> points = Queue();
1019+
Paint painter = Paint();
1020+
1021+
TrackPainter(this.points);
1022+
1023+
@override
1024+
void paint(Canvas canvas, Size size) {
1025+
canvas.drawPoints(PointMode.polygon, points.toList(), painter);
1026+
}
1027+
1028+
@override
1029+
bool shouldRepaint(CustomPainter oldDelegate) => true;
1030+
}
1031+
10171032
class TranslateExampleState extends State<TranslateExample> {
10181033
late Timer timer;
10191034
double angle = 0;
10201035
double earthRevolutionAngle = 0;
1036+
Queue<Offset> points = Queue();
10211037
10221038
@override
10231039
void initState() {
@@ -1046,6 +1062,12 @@ class TranslateExampleState extends State<TranslateExample> {
10461062
),
10471063
body: ConstraintLayout(
10481064
children: [
1065+
CustomPaint(
1066+
painter: TrackPainter(points),
1067+
).applyConstraint(
1068+
width: matchParent,
1069+
height: matchParent,
1070+
),
10491071
Container(
10501072
decoration: const BoxDecoration(
10511073
color: Colors.redAccent,
@@ -1106,6 +1128,12 @@ class TranslateExampleState extends State<TranslateExample> {
11061128
angle: earthRevolutionAngle * 365 / 27.32,
11071129
),
11081130
translateConstraint: true,
1131+
paintCallback: (_, __, ____, offset, ______) {
1132+
points.add(offset!);
1133+
if (points.length > 2000) {
1134+
points.removeFirst();
1135+
}
1136+
},
11091137
),
11101138
Text('Sun rotates ${(earthRevolutionAngle * 365 / 25.4) ~/ 360} times')
11111139
.applyConstraint(

example/charts.dart

+7-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import 'dart:collection';
21
import 'dart:math';
2+
import 'dart:ui';
33

44
import 'package:flutter/material.dart';
55
import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
@@ -14,7 +14,7 @@ class ChartsExample extends StatefulWidget {
1414
}
1515

1616
class PolylinePainter extends CustomPainter {
17-
Map<int, Rect> polylineData;
17+
List<Offset> polylineData;
1818

1919
PolylinePainter(this.polylineData);
2020

@@ -26,18 +26,7 @@ class PolylinePainter extends CustomPainter {
2626
Paint paint = Paint()
2727
..strokeWidth = 1
2828
..color = Colors.green;
29-
List<Rect> rectList = polylineData.values.toList();
30-
Rect last = rectList[0];
31-
Rect current;
32-
for (int i = 1; i < rectList.length; i++) {
33-
current = rectList[i];
34-
canvas.drawLine(
35-
Offset(last.left + last.width / 2, last.top + last.height),
36-
Offset(
37-
current.left + current.width / 2, current.top + current.height),
38-
paint);
39-
last = current;
40-
}
29+
canvas.drawPoints(PointMode.polygon, polylineData, paint);
4130
}
4231
}
4332

@@ -47,7 +36,7 @@ class ChartsState extends State<ChartsExample> {
4736
late List<int> compareData;
4837
late int maxValue;
4938
int current = 6;
50-
Map<int, Rect> polylineData = HashMap();
39+
late List<Offset> polylineData;
5140
ScrollController controller = ScrollController();
5241

5342
@override
@@ -58,6 +47,7 @@ class ChartsState extends State<ChartsExample> {
5847
data = [for (int i = 0; i < xTitles.length; i++) 10 + random.nextInt(91)];
5948
compareData = data.toList()..shuffle();
6049
maxValue = data.reduce(max);
50+
polylineData = List.filled(data.length, Offset.zero);
6151
}
6252

6353
@override
@@ -179,8 +169,8 @@ class ChartsState extends State<ChartsExample> {
179169
.bottomMargin((compareData[i] / maxValue) * 400),
180170
translate: const Offset(0, 0.5),
181171
percentageTranslate: true,
182-
callback: (_, rect) {
183-
polylineData[i] = rect;
172+
layoutCallback: (_, rect) {
173+
polylineData[i] = rect.bottomCenter;
184174
},
185175
),
186176
Container(

example/translate.dart

+30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'dart:async';
2+
import 'dart:collection';
3+
import 'dart:ui';
24

35
import 'package:flutter/material.dart';
46
import 'package:flutter_constraintlayout/flutter_constraintlayout.dart';
@@ -12,10 +14,26 @@ class TranslateExample extends StatefulWidget {
1214
State createState() => TranslateExampleState();
1315
}
1416

17+
class TrackPainter extends CustomPainter {
18+
Queue<Offset> points = Queue();
19+
Paint painter = Paint();
20+
21+
TrackPainter(this.points);
22+
23+
@override
24+
void paint(Canvas canvas, Size size) {
25+
canvas.drawPoints(PointMode.polygon, points.toList(), painter);
26+
}
27+
28+
@override
29+
bool shouldRepaint(CustomPainter oldDelegate) => true;
30+
}
31+
1532
class TranslateExampleState extends State<TranslateExample> {
1633
late Timer timer;
1734
double angle = 0;
1835
double earthRevolutionAngle = 0;
36+
Queue<Offset> points = Queue();
1937

2038
@override
2139
void initState() {
@@ -44,6 +62,12 @@ class TranslateExampleState extends State<TranslateExample> {
4462
),
4563
body: ConstraintLayout(
4664
children: [
65+
CustomPaint(
66+
painter: TrackPainter(points),
67+
).applyConstraint(
68+
width: matchParent,
69+
height: matchParent,
70+
),
4771
Container(
4872
decoration: const BoxDecoration(
4973
color: Colors.redAccent,
@@ -104,6 +128,12 @@ class TranslateExampleState extends State<TranslateExample> {
104128
angle: earthRevolutionAngle * 365 / 27.32,
105129
),
106130
translateConstraint: true,
131+
paintCallback: (_, __, ____, offset, ______) {
132+
points.add(offset!);
133+
if (points.length > 2000) {
134+
points.removeFirst();
135+
}
136+
},
107137
),
108138
Text('Sun rotates ${(earthRevolutionAngle * 365 / 25.4) ~/ 360} times')
109139
.applyConstraint(

example/wrapper_constraints.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class WrapperConstraintsExampleState extends State<WrapperConstraintsExample> {
6161
),
6262
item('centerTopRightTo').applyConstraint(
6363
centerTopRightTo: rId(0),
64-
callback: (_, rect) {
64+
layoutCallback: (_, rect) {
6565
leftX = rect.right;
6666
},
6767
),
@@ -92,7 +92,7 @@ class WrapperConstraintsExampleState extends State<WrapperConstraintsExample> {
9292
),
9393
item('outTopLeftTo').applyConstraint(
9494
outTopLeftTo: rId(1),
95-
callback: (_, rect) {
95+
layoutCallback: (_, rect) {
9696
rightX = rect.left;
9797
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
9898
setState(() {});

lib/flutter_constraintlayout.dart

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ library flutter_constraintlayout;
22

33
export 'src/core.dart';
44
export 'src/extensions.dart';
5-
export 'src/auxiliary.dart';

0 commit comments

Comments
 (0)