Unverified Commit 7d368dcf authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

InteractiveViewer with a child of zero size (#90012)

Asserts that the InteractiveViewer child can't have zero size.
parent 2b4ef184
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment