Unverified Commit b1c4d568 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

Fix widget inspector null check (#120143)

* add failing test

* fix

* remove extra whitespace

* fix test failure

* disable trackrebuilddirtywidgets in teardown

* remove no-shuffle annotation

* fix
parent 0fb4406c
......@@ -2455,7 +2455,10 @@ class _ElementLocationStatsTracker {
return;
}
final _HasCreationLocation creationLocationSource = widget;
final _Location location = creationLocationSource._location;
final _Location? location = creationLocationSource._location;
if (location == null) {
return;
}
final int id = _toLocationId(location);
_LocationCount entry;
......@@ -3279,7 +3282,7 @@ const TextStyle _messageStyle = TextStyle(
/// {@macro flutter.widgets.WidgetInspectorService.getChildrenSummaryTree}
// ignore: unused_element
abstract class _HasCreationLocation {
_Location get _location;
_Location? get _location;
}
/// A tuple with file, line, and column number, for displaying human-readable
......
......@@ -10,7 +10,7 @@
// reduced-test-set:
// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set', 'no-shuffle'])
@Tags(<String>['reduced-test-set'])
@TestOn('!chrome')
library;
......@@ -220,6 +220,14 @@ class RepaintBoundaryWithDebugPaint extends RepaintBoundary {
}
}
Widget _applyConstructor(Widget Function() constructor) => constructor();
class _TrivialWidget extends StatelessWidget {
const _TrivialWidget() : super(key: const Key('singleton'));
@override
Widget build(BuildContext context) => const Text('Hello, world!');
}
int getChildLayerCount(OffsetLayer layer) {
Layer? child = layer.firstChild;
int count = 0;
......@@ -240,8 +248,15 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
final TestWidgetInspectorService service = TestWidgetInspectorService();
WidgetInspectorService.instance = service;
tearDown(() {
tearDown(() async {
service.resetAllState();
if (WidgetInspectorService.instance.isWidgetCreationTracked()) {
await service.testBoolExtension(
WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name,
<String, String>{'enabled': 'false'},
);
}
});
testWidgets('WidgetInspector smoke test', (WidgetTester tester) async {
......@@ -3586,6 +3601,28 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag.
);
testWidgets('ext.flutter.inspector.trackRebuildDirtyWidgets with tear-offs', (WidgetTester tester) async {
final Widget widget = Directionality(
textDirection: TextDirection.ltr,
child: WidgetInspector(
selectButtonBuilder: null,
child: _applyConstructor(_TrivialWidget.new),
),
);
expect(
await service.testBoolExtension(
WidgetInspectorServiceExtensions.trackRebuildDirtyWidgets.name,
<String, String>{'enabled': 'true'},
),
equals('true'),
);
await tester.pumpWidget(widget);
},
skip: !WidgetInspectorService.instance.isWidgetCreationTracked(), // [intended] Test requires --track-widget-creation flag.
);
testWidgets('ext.flutter.inspector.trackRebuildDirtyWidgets', (WidgetTester tester) async {
service.rebuildCount = 0;
......
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