@@ -19,33 +19,38 @@ void main() {
19
19
);
20
20
}
21
21
22
- expect (
23
- tester.widget (find.byType (Positioned )),
24
- isPositionedAt (Offset .zero),
25
- );
26
-
27
- final Offset centerOfFlutterLogo = tester.getCenter (find.byType (Positioned ));
28
- final Offset topLeftOfFlutterLogo = tester.getTopLeft (find.byType (FlutterLogo ));
29
-
22
+ // Make sure magnifier is present.
23
+ final Finder positionedWidget = find.byType (Positioned );
24
+ final Widget positionedWidgetInTree = tester.widget (positionedWidget);
25
+ final Positioned oldConcretePositioned = positionedWidgetInTree as Positioned ;
26
+ expect (positionedWidget, findsOneWidget);
27
+
28
+ // Confirm if magnifier is in the center of the FlutterLogo.
29
+ final Offset centerOfPositioned = tester.getCenter (positionedWidget);
30
+ final Offset centerOfFlutterLogo = tester.getCenter (find.byType (FlutterLogo ));
31
+ expect (centerOfPositioned, equals (centerOfFlutterLogo));
32
+
33
+ // Drag the magnifier and confirm its new position is expected.
30
34
const Offset dragDistance = Offset (10 , 10 );
31
-
32
- await tester.dragFrom (centerOfFlutterLogo, dragDistance);
35
+ final Offset updatedPositioned = Offset (
36
+ oldConcretePositioned.left ?? 0.0 + 10.0 ,
37
+ oldConcretePositioned.top ?? 0.0 + 10.0 ,
38
+ );
39
+ await tester.dragFrom (centerOfPositioned, dragDistance);
33
40
await tester.pump ();
34
-
35
41
expect (
36
- tester.widget (find.byType (Positioned )),
37
- // Need to adjust by the topleft since the position is local.
38
- isPositionedAt ((centerOfFlutterLogo - topLeftOfFlutterLogo) + dragDistance),
42
+ positionedWidgetInTree,
43
+ isPositionedAt (updatedPositioned),
39
44
);
40
45
});
41
46
42
47
testWidgets ('should match golden' , (WidgetTester tester) async {
43
48
await tester.pumpWidget (const example.MagnifierExampleApp ());
44
49
45
- final Offset centerOfFlutterLogo = tester.getCenter (find.byType (Positioned ));
50
+ final Offset centerOfPositioned = tester.getCenter (find.byType (Positioned ));
46
51
const Offset dragDistance = Offset (10 , 10 );
47
52
48
- await tester.dragFrom (centerOfFlutterLogo , dragDistance);
53
+ await tester.dragFrom (centerOfPositioned , dragDistance);
49
54
await tester.pump ();
50
55
51
56
await expectLater (
0 commit comments