Skip to content

Commit

Permalink
Move debugShowWidgetInspectorOverride (flutter#144029)
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c authored Feb 26, 2024
1 parent 7b5ec58 commit 523b0c4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 31 deletions.
21 changes: 1 addition & 20 deletions packages/flutter/lib/src/widgets/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1193,25 +1193,6 @@ class WidgetsApp extends StatefulWidget {
/// Used by the `showPerformanceOverlay` VM service extension.
static bool showPerformanceOverlayOverride = false;

/// If true, forces the widget inspector to be visible.
///
/// Overrides the `debugShowWidgetInspector` value set in [WidgetsApp].
///
/// Used by the `debugShowWidgetInspector` debugging extension.
///
/// The inspector allows the selection of a location on your device or emulator
/// and view what widgets and render objects associated with it. An outline of
/// the selected widget and some summary information is shown on device and
/// more detailed information is shown in the IDE or DevTools.
static bool get debugShowWidgetInspectorOverride {
return _debugShowWidgetInspectorOverrideNotifier.value;
}
static set debugShowWidgetInspectorOverride(bool value) {
_debugShowWidgetInspectorOverrideNotifier.value = value;
}

static final ValueNotifier<bool> _debugShowWidgetInspectorOverrideNotifier = ValueNotifier<bool>(false);

/// If false, prevents the debug banner from being visible.
///
/// Used by the `debugAllowBanner` VM service extension.
Expand Down Expand Up @@ -1760,7 +1741,7 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {

assert(() {
result = ValueListenableBuilder<bool>(
valueListenable: WidgetsApp._debugShowWidgetInspectorOverrideNotifier,
valueListenable: WidgetsBinding.instance.debugShowWidgetInspectorOverrideNotifier,
builder: (BuildContext context, bool debugShowWidgetInspectorOverride, Widget? child) {
if (widget.debugShowWidgetInspector || debugShowWidgetInspectorOverride) {
return WidgetInspector(
Expand Down
30 changes: 30 additions & 0 deletions packages/flutter/lib/src/widgets/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,36 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
static WidgetsBinding get instance => BindingBase.checkInstance(_instance);
static WidgetsBinding? _instance;

/// If true, forces the widget inspector to be visible.
///
/// Overrides the `debugShowWidgetInspector` value set in [WidgetsApp].
///
/// Used by the `debugShowWidgetInspector` debugging extension.
///
/// The inspector allows the selection of a location on your device or emulator
/// and view what widgets and render objects associated with it. An outline of
/// the selected widget and some summary information is shown on device and
/// more detailed information is shown in the IDE or DevTools.
bool get debugShowWidgetInspectorOverride {
return debugShowWidgetInspectorOverrideNotifier.value;
}
set debugShowWidgetInspectorOverride(bool value) {
debugShowWidgetInspectorOverrideNotifier.value = value;
}

/// Notifier for [debugShowWidgetInspectorOverride].
ValueNotifier<bool> get debugShowWidgetInspectorOverrideNotifier => _debugShowWidgetInspectorOverrideNotifierObject ??= ValueNotifier<bool>(false);
ValueNotifier<bool>? _debugShowWidgetInspectorOverrideNotifierObject;

@visibleForTesting
@override
void resetInternalState() {
// ignore: invalid_use_of_visible_for_testing_member, https://github.com/dart-lang/sdk/issues/41998
super.resetInternalState();
_debugShowWidgetInspectorOverrideNotifierObject?.dispose();
_debugShowWidgetInspectorOverrideNotifierObject = null;
}

void _debugAddStackFilters() {
const PartialStackFrame elementInflateWidget = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'Element', method: 'inflateWidget');
const PartialStackFrame elementUpdateChild = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'Element', method: 'updateChild');
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/service_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ enum WidgetInspectorServiceExtensions {
structuredErrors,

/// Name of service extension that, when called, will change the value of
/// [WidgetsApp.debugShowWidgetInspectorOverride], which controls whether the
/// [WidgetsBinding.debugShowWidgetInspectorOverride], which controls whether the
/// on-device widget inspector is visible.
///
/// See also:
/// * [WidgetsApp.debugShowWidgetInspectorOverride], which is the flag that
/// * [WidgetsBinding.debugShowWidgetInspectorOverride], which is the flag that
/// this service extension exposes.
/// * [WidgetInspectorService.initServiceExtensions], where the service
/// extension is registered.
Expand Down
7 changes: 3 additions & 4 deletions packages/flutter/lib/src/widgets/widget_inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:meta/meta_meta.dart';

import 'app.dart';
import 'basic.dart';
import 'binding.dart';
import 'debug.dart';
Expand Down Expand Up @@ -1084,10 +1083,10 @@ mixin WidgetInspectorService {

_registerBoolServiceExtension(
name: WidgetInspectorServiceExtensions.show.name,
getter: () async => WidgetsApp.debugShowWidgetInspectorOverride,
getter: () async => WidgetsBinding.instance.debugShowWidgetInspectorOverride,
setter: (bool value) {
if (WidgetsApp.debugShowWidgetInspectorOverride != value) {
WidgetsApp.debugShowWidgetInspectorOverride = value;
if (WidgetsBinding.instance.debugShowWidgetInspectorOverride != value) {
WidgetsBinding.instance.debugShowWidgetInspectorOverride = value;
}
return Future<void>.value();
},
Expand Down
7 changes: 5 additions & 2 deletions packages/flutter/test/painting/system_fonts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ Future<void> verifyMarkedNeedsLayoutDuringTransientCallbacksPhase(WidgetTester t
}

void main() {
testWidgets('RenderParagraph relayout upon system fonts changes',
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
LeakTesting.settings = LeakTesting.settings.withIgnored(classes: <String>['CurvedAnimation']);

testWidgets('RenderParagraph relayout upon system fonts changes',
// TODO(polina-c): dispose _NotAnnounced, https://github.com/dart-lang/leak_tracker/issues/218 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnored(classes: <String>['ValueNotifier<String?>', '_NotAnnounced']),
(WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/test/widgets/widget_inspector_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4130,7 +4130,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
debugShowChangeCounter++;
}

WidgetsApp.debugShowWidgetInspectorOverride = false;
WidgetsBinding.instance.debugShowWidgetInspectorOverride = false;
valueListenableBuilderWidget.valueListenable.addListener(debugShowWidgetInspectorOverrideCallback);

service.rebuildCount = 0;
Expand All @@ -4155,7 +4155,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
),
equals('true'),
);
expect(WidgetsApp.debugShowWidgetInspectorOverride, isTrue);
expect(WidgetsBinding.instance.debugShowWidgetInspectorOverride, isTrue);
expect(extensionChangedEvents.length, equals(1));
expect(service.rebuildCount, equals(0)); // Should not be force rebuilt.
expect(debugShowChangeCounter, equals(1));
Expand Down Expand Up @@ -4195,7 +4195,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
expect(extensionChangedEvents.length, equals(3));
expect(service.rebuildCount, equals(0)); // Should not be force rebuilt.
expect(debugShowChangeCounter, equals(2));
expect(WidgetsApp.debugShowWidgetInspectorOverride, isFalse);
expect(WidgetsBinding.instance.debugShowWidgetInspectorOverride, isFalse);
});

testWidgets('ext.flutter.inspector.screenshot', (WidgetTester tester) async {
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter_test/lib/src/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,8 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
keyEventManager.clearState();
// ignore: invalid_use_of_visible_for_testing_member
RendererBinding.instance.initMouseTracker();

assert(ServicesBinding.instance == WidgetsBinding.instance);
// ignore: invalid_use_of_visible_for_testing_member
ServicesBinding.instance.resetInternalState();
}
Expand Down

0 comments on commit 523b0c4

Please sign in to comment.