mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
InteractiveViewer with a child of zero size (#90012)
Asserts that the InteractiveViewer child can't have zero size.
This commit is contained in:
parent
2b4ef184b7
commit
7d368dcf0c
@ -512,6 +512,10 @@ class _InteractiveViewerState extends State<InteractiveViewer> with TickerProvid
|
||||
final RenderBox childRenderBox = _childKey.currentContext!.findRenderObject()! as RenderBox;
|
||||
final Size childSize = childRenderBox.size;
|
||||
final Rect boundaryRect = widget.boundaryMargin.inflateRect(Offset.zero & childSize);
|
||||
assert(
|
||||
!boundaryRect.isEmpty,
|
||||
"InteractiveViewer's child must have nonzero dimensions.",
|
||||
);
|
||||
// Boundaries that are partially infinite are not allowed because Matrix4's
|
||||
// rotation and translation methods don't handle infinites well.
|
||||
assert(
|
||||
|
||||
@ -201,6 +201,42 @@ void main() {
|
||||
expect(transformationController.value, isNot(equals(Matrix4.identity())));
|
||||
});
|
||||
|
||||
testWidgets('child has no dimensions', (WidgetTester tester) async {
|
||||
final TransformationController transformationController = TransformationController();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: InteractiveViewer(
|
||||
constrained: false,
|
||||
scaleEnabled: false,
|
||||
transformationController: transformationController,
|
||||
child: const SizedBox(width: 0.0, height: 0.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(transformationController.value, equals(Matrix4.identity()));
|
||||
|
||||
// Interacting throws an error because the child has no size.
|
||||
final Offset childOffset = tester.getTopLeft(find.byType(SizedBox));
|
||||
final Offset childInterior = Offset(
|
||||
childOffset.dx + 20.0,
|
||||
childOffset.dy + 20.0,
|
||||
);
|
||||
final TestGesture gesture = await tester.startGesture(childOffset);
|
||||
addTearDown(gesture.removePointer);
|
||||
await tester.pump();
|
||||
await gesture.moveTo(childInterior);
|
||||
await tester.pump();
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(transformationController.value, equals(Matrix4.identity()));
|
||||
expect(tester.takeException(), isAssertionError);
|
||||
});
|
||||
|
||||
testWidgets('no boundary', (WidgetTester tester) async {
|
||||
final TransformationController transformationController = TransformationController();
|
||||
const double minScale = 0.8;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user