Unverified Commit 523b0c4d authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

Move debugShowWidgetInspectorOverride (#144029)

Contributes to https://github.com/dart-lang/leak_tracker/issues/218
parent 7b5ec588
......@@ -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.
......@@ -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(
......
......@@ -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');
......
......@@ -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.
......
......@@ -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';
......@@ -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();
},
......
......@@ -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(
......
......@@ -4130,7 +4130,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
debugShowChangeCounter++;
}
WidgetsApp.debugShowWidgetInspectorOverride = false;
WidgetsBinding.instance.debugShowWidgetInspectorOverride = false;
valueListenableBuilderWidget.valueListenable.addListener(debugShowWidgetInspectorOverrideCallback);
service.rebuildCount = 0;
......@@ -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));
......@@ -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 {
......
......@@ -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();
}
......
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