Skip to content

Commit 9b15c2e

Browse files
authored
[dynamic_layouts] relax layout test to fix tree (flutter#4677)
A current roll from the engine to flutter/flutter to packages has broken this test value by a small amount. I wrote a small function to manage tolerances. Let me know if this is a reasonable way to manage this for now.
1 parent 8248ef2 commit 9b15c2e

2 files changed

Lines changed: 36 additions & 22 deletions

File tree

.ci/flutter_master.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f4c25bbb351cc59ffdefe980c0c993196a8a6d47
1+
685141bf3b5ff4a90589fd77784776e011dd5fcc

packages/dynamic_layouts/example/test/wrap_example_test.dart

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,33 @@
33
// found in the LICENSE file.
44

55
import 'package:example/wrap_layout_example.dart';
6-
import 'package:flutter/foundation.dart';
76
import 'package:flutter/material.dart';
87
import 'package:flutter_test/flutter_test.dart';
98

109
void main() {
10+
void withinTolerance(Offset actual, Offset expected, double tolerance) {
11+
expect(
12+
actual.dx,
13+
(double actual) => actual <= expected.dx + tolerance,
14+
reason: '${actual.dx} <= ${expected.dx + tolerance}',
15+
);
16+
expect(
17+
actual.dx,
18+
(double actual) => actual >= expected.dx - tolerance,
19+
reason: '${actual.dx} >= ${expected.dx - tolerance}',
20+
);
21+
expect(
22+
actual.dy,
23+
(double actual) => actual <= expected.dy + tolerance,
24+
reason: '${actual.dy} <= ${expected.dy + tolerance}',
25+
);
26+
expect(
27+
actual.dy,
28+
(double actual) => actual >= expected.dy - tolerance,
29+
reason: '${actual.dy} >= ${expected.dy - tolerance}',
30+
);
31+
}
32+
1133
testWidgets('Check that the children are layed out.',
1234
(WidgetTester tester) async {
1335
const MaterialApp app = MaterialApp(
@@ -25,27 +47,19 @@ void main() {
2547

2648
// Material 3 changes the expected layout positioning.
2749
final bool usesMaterial3 = (app.theme ?? ThemeData.light()).useMaterial3;
28-
final Offset offset0 = usesMaterial3
29-
? Offset(0.0, _getExpectedYOffset(91.0))
30-
: const Offset(0.0, 103.0);
31-
final Offset offset1 = usesMaterial3
32-
? Offset(65.0, _getExpectedYOffset(121.0))
33-
: const Offset(66.0, 124.0);
34-
final Offset offset3 = usesMaterial3
35-
? Offset(270.0, _getExpectedYOffset(171.0))
36-
: const Offset(271.0, 174.0);
37-
final Offset offset4 = usesMaterial3
38-
? Offset(380.0, _getExpectedYOffset(221.0))
39-
: const Offset(381.0, 224.0);
50+
final Offset offset0 =
51+
usesMaterial3 ? const Offset(0.0, 91.0) : const Offset(0.0, 103.0);
52+
final Offset offset1 =
53+
usesMaterial3 ? const Offset(65.0, 121.0) : const Offset(66.0, 124.0);
54+
final Offset offset3 =
55+
usesMaterial3 ? const Offset(270.0, 171.0) : const Offset(271.0, 174.0);
56+
final Offset offset4 =
57+
usesMaterial3 ? const Offset(380.0, 221.0) : const Offset(381.0, 224.0);
4058

4159
// See if they are in expected position.
42-
expect(tester.getTopLeft(find.text('Index 0')), offset0);
43-
expect(tester.getTopLeft(find.text('Index 1')), offset1);
44-
expect(tester.getTopLeft(find.text('Index 3')), offset3);
45-
expect(tester.getTopLeft(find.text('Index 4')), offset4);
60+
withinTolerance(tester.getTopLeft(find.text('Index 0')), offset0, 0.2);
61+
withinTolerance(tester.getTopLeft(find.text('Index 1')), offset1, 0.2);
62+
withinTolerance(tester.getTopLeft(find.text('Index 3')), offset3, 0.2);
63+
withinTolerance(tester.getTopLeft(find.text('Index 4')), offset4, 0.2);
4664
});
4765
}
48-
49-
double _getExpectedYOffset(double nonWeb) {
50-
return kIsWeb ? nonWeb - 0.5 : nonWeb;
51-
}

0 commit comments

Comments
 (0)