Enhances intuitiveness of RawMagnifier's example (#150308)
### Demo | Before | After | | --------------- | --------------- | <video src="https://github.com/flutter/flutter/assets/104349824/ee6d45f1-bcf0-4136-8d1d-a642e0767322"/> | <video src="https://github.com/flutter/flutter/assets/104349824/1e2bb33d-40f1-4cf6-9999-f67bef638633"/> ### Related issue Fixes https://github.com/flutter/flutter/issues/150307
This commit is contained in:
@@ -19,33 +19,38 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
expect(
|
||||
tester.widget(find.byType(Positioned)),
|
||||
isPositionedAt(Offset.zero),
|
||||
);
|
||||
// Make sure magnifier is present.
|
||||
final Finder positionedWidget = find.byType(Positioned);
|
||||
final Widget positionedWidgetInTree = tester.widget(positionedWidget);
|
||||
final Positioned oldConcretePositioned = positionedWidgetInTree as Positioned;
|
||||
expect(positionedWidget, findsOneWidget);
|
||||
|
||||
final Offset centerOfFlutterLogo = tester.getCenter(find.byType(Positioned));
|
||||
final Offset topLeftOfFlutterLogo = tester.getTopLeft(find.byType(FlutterLogo));
|
||||
// Confirm if magnifier is in the center of the FlutterLogo.
|
||||
final Offset centerOfPositioned = tester.getCenter(positionedWidget);
|
||||
final Offset centerOfFlutterLogo = tester.getCenter(find.byType(FlutterLogo));
|
||||
expect(centerOfPositioned, equals(centerOfFlutterLogo));
|
||||
|
||||
// Drag the magnifier and confirm its new position is expected.
|
||||
const Offset dragDistance = Offset(10, 10);
|
||||
|
||||
await tester.dragFrom(centerOfFlutterLogo, dragDistance);
|
||||
final Offset updatedPositioned = Offset(
|
||||
oldConcretePositioned.left ?? 0.0 + 10.0,
|
||||
oldConcretePositioned.top ?? 0.0 + 10.0,
|
||||
);
|
||||
await tester.dragFrom(centerOfPositioned, dragDistance);
|
||||
await tester.pump();
|
||||
|
||||
expect(
|
||||
tester.widget(find.byType(Positioned)),
|
||||
// Need to adjust by the topleft since the position is local.
|
||||
isPositionedAt((centerOfFlutterLogo - topLeftOfFlutterLogo) + dragDistance),
|
||||
positionedWidgetInTree,
|
||||
isPositionedAt(updatedPositioned),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('should match golden', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const example.MagnifierExampleApp());
|
||||
|
||||
final Offset centerOfFlutterLogo = tester.getCenter(find.byType(Positioned));
|
||||
final Offset centerOfPositioned = tester.getCenter(find.byType(Positioned));
|
||||
const Offset dragDistance = Offset(10, 10);
|
||||
|
||||
await tester.dragFrom(centerOfFlutterLogo, dragDistance);
|
||||
await tester.dragFrom(centerOfPositioned, dragDistance);
|
||||
await tester.pump();
|
||||
|
||||
await expectLater(
|
||||
|
||||
Reference in New Issue
Block a user