33// found in the LICENSE file.
44
55import 'package:example/wrap_layout_example.dart' ;
6+ import 'package:flutter/foundation.dart' ;
67import 'package:flutter/material.dart' ;
78import 'package:flutter_test/flutter_test.dart' ;
89
910void main () {
1011 testWidgets ('Check that the children are layed out.' ,
1112 (WidgetTester tester) async {
12- await tester.pumpWidget (
13- const MaterialApp (
14- home: WrapExample (),
15- ),
13+ const MaterialApp app = MaterialApp (
14+ home: WrapExample (),
1615 );
16+ await tester.pumpWidget (app);
1717 await tester.pumpAndSettle ();
1818
1919 // See if there are children layed out.
@@ -23,10 +23,29 @@ void main() {
2323 expect (find.text ('Index 3' ), findsOneWidget);
2424 expect (find.text ('Index 4' ), findsOneWidget);
2525
26+ // Material 3 changes the expected layout positioning.
27+ 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 );
40+
2641 // See if they are in expected position.
27- expect (tester.getTopLeft (find.text ('Index 0' )), const Offset ( 0.0 , 103.0 ) );
28- expect (tester.getTopLeft (find.text ('Index 1' )), const Offset ( 66.0 , 124.0 ) );
29- expect (tester.getTopLeft (find.text ('Index 3' )), const Offset ( 271.0 , 174.0 ) );
30- expect (tester.getTopLeft (find.text ('Index 4' )), const Offset ( 381.0 , 224.0 ) );
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 );
3146 });
3247}
48+
49+ double _getExpectedYOffset (double nonWeb) {
50+ return kIsWeb ? nonWeb - 0.5 : nonWeb;
51+ }
0 commit comments