33// found in the LICENSE file.
44
55import 'package:example/wrap_layout_example.dart' ;
6- import 'package:flutter/foundation.dart' ;
76import 'package:flutter/material.dart' ;
87import 'package:flutter_test/flutter_test.dart' ;
98
109void 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