Make the inspector handle widgets with non-invertible transforms gracefully. (#15761)

This commit is contained in:
Jacob Richman 2018-03-20 16:38:19 -07:00 committed by GitHub
parent 19ef85bf6c
commit 4e5acef664
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -564,7 +564,14 @@ class _WidgetInspectorState extends State<WidgetInspector>
Matrix4 transform,
) {
bool hit = false;
final Matrix4 inverse = new Matrix4.inverted(transform);
Matrix4 inverse;
try {
inverse = new Matrix4.inverted(transform);
} on ArgumentError {
// We cannot invert the transform. That means the object doesn't appear on
// screen and cannot be hit.
return false;
}
final Offset localPosition = MatrixUtils.transformPoint(inverse, position);
final List<DiagnosticsNode> children = object.debugDescribeChildren();

View File

@ -117,6 +117,31 @@ void main() {
expect(paragraphText(getInspectorState().selection.current), equals('BOTTOM'));
});
testWidgets('WidgetInspector non-invertible transform regression test', (WidgetTester tester) async {
await tester.pumpWidget(
new Directionality(
textDirection: TextDirection.ltr,
child: new WidgetInspector(
selectButtonBuilder: null,
child: new Transform(
transform: new Matrix4.identity()..scale(0.0),
child: new Stack(
children: const <Widget>[
const Text('a', textDirection: TextDirection.ltr),
const Text('b', textDirection: TextDirection.ltr),
const Text('c', textDirection: TextDirection.ltr),
],
),
),
),
),
);
await tester.tap(find.byType(Transform));
expect(true, isTrue); // Expect that we reach here without crashing.
});
testWidgets('WidgetInspector scroll test', (WidgetTester tester) async {
final Key childKey = new UniqueKey();
final GlobalKey selectButtonKey = new GlobalKey();