mirror of
https://github.com/flutter/flutter
synced 2024-08-25 11:07:06 +00:00
Move debugShowWidgetInspectorOverride (#144029)
Contributes to https://github.com/dart-lang/leak_tracker/issues/218
This commit is contained in:
parent
7b5ec588d1
commit
523b0c4d84
|
@ -1193,25 +1193,6 @@ class WidgetsApp extends StatefulWidget {
|
||||||
/// Used by the `showPerformanceOverlay` VM service extension.
|
/// Used by the `showPerformanceOverlay` VM service extension.
|
||||||
static bool showPerformanceOverlayOverride = false;
|
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.
|
/// If false, prevents the debug banner from being visible.
|
||||||
///
|
///
|
||||||
/// Used by the `debugAllowBanner` VM service extension.
|
/// Used by the `debugAllowBanner` VM service extension.
|
||||||
|
@ -1760,7 +1741,7 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
|
||||||
|
|
||||||
assert(() {
|
assert(() {
|
||||||
result = ValueListenableBuilder<bool>(
|
result = ValueListenableBuilder<bool>(
|
||||||
valueListenable: WidgetsApp._debugShowWidgetInspectorOverrideNotifier,
|
valueListenable: WidgetsBinding.instance.debugShowWidgetInspectorOverrideNotifier,
|
||||||
builder: (BuildContext context, bool debugShowWidgetInspectorOverride, Widget? child) {
|
builder: (BuildContext context, bool debugShowWidgetInspectorOverride, Widget? child) {
|
||||||
if (widget.debugShowWidgetInspector || debugShowWidgetInspectorOverride) {
|
if (widget.debugShowWidgetInspector || debugShowWidgetInspectorOverride) {
|
||||||
return WidgetInspector(
|
return WidgetInspector(
|
||||||
|
|
|
@ -375,6 +375,36 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
|
||||||
static WidgetsBinding get instance => BindingBase.checkInstance(_instance);
|
static WidgetsBinding get instance => BindingBase.checkInstance(_instance);
|
||||||
static WidgetsBinding? _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() {
|
void _debugAddStackFilters() {
|
||||||
const PartialStackFrame elementInflateWidget = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'Element', method: 'inflateWidget');
|
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');
|
const PartialStackFrame elementUpdateChild = PartialStackFrame(package: 'package:flutter/src/widgets/framework.dart', className: 'Element', method: 'updateChild');
|
||||||
|
|
|
@ -123,11 +123,11 @@ enum WidgetInspectorServiceExtensions {
|
||||||
structuredErrors,
|
structuredErrors,
|
||||||
|
|
||||||
/// Name of service extension that, when called, will change the value of
|
/// 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.
|
/// on-device widget inspector is visible.
|
||||||
///
|
///
|
||||||
/// See also:
|
/// See also:
|
||||||
/// * [WidgetsApp.debugShowWidgetInspectorOverride], which is the flag that
|
/// * [WidgetsBinding.debugShowWidgetInspectorOverride], which is the flag that
|
||||||
/// this service extension exposes.
|
/// this service extension exposes.
|
||||||
/// * [WidgetInspectorService.initServiceExtensions], where the service
|
/// * [WidgetInspectorService.initServiceExtensions], where the service
|
||||||
/// extension is registered.
|
/// extension is registered.
|
||||||
|
|
|
@ -25,7 +25,6 @@ import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
import 'package:flutter/scheduler.dart';
|
||||||
import 'package:meta/meta_meta.dart';
|
import 'package:meta/meta_meta.dart';
|
||||||
|
|
||||||
import 'app.dart';
|
|
||||||
import 'basic.dart';
|
import 'basic.dart';
|
||||||
import 'binding.dart';
|
import 'binding.dart';
|
||||||
import 'debug.dart';
|
import 'debug.dart';
|
||||||
|
@ -1084,10 +1083,10 @@ mixin WidgetInspectorService {
|
||||||
|
|
||||||
_registerBoolServiceExtension(
|
_registerBoolServiceExtension(
|
||||||
name: WidgetInspectorServiceExtensions.show.name,
|
name: WidgetInspectorServiceExtensions.show.name,
|
||||||
getter: () async => WidgetsApp.debugShowWidgetInspectorOverride,
|
getter: () async => WidgetsBinding.instance.debugShowWidgetInspectorOverride,
|
||||||
setter: (bool value) {
|
setter: (bool value) {
|
||||||
if (WidgetsApp.debugShowWidgetInspectorOverride != value) {
|
if (WidgetsBinding.instance.debugShowWidgetInspectorOverride != value) {
|
||||||
WidgetsApp.debugShowWidgetInspectorOverride = value;
|
WidgetsBinding.instance.debugShowWidgetInspectorOverride = value;
|
||||||
}
|
}
|
||||||
return Future<void>.value();
|
return Future<void>.value();
|
||||||
},
|
},
|
||||||
|
|
|
@ -37,9 +37,12 @@ Future<void> verifyMarkedNeedsLayoutDuringTransientCallbacksPhase(WidgetTester t
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
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]
|
// 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 {
|
(WidgetTester tester) async {
|
||||||
await tester.pumpWidget(
|
await tester.pumpWidget(
|
||||||
const MaterialApp(
|
const MaterialApp(
|
||||||
|
|
|
@ -4130,7 +4130,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
||||||
debugShowChangeCounter++;
|
debugShowChangeCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetsApp.debugShowWidgetInspectorOverride = false;
|
WidgetsBinding.instance.debugShowWidgetInspectorOverride = false;
|
||||||
valueListenableBuilderWidget.valueListenable.addListener(debugShowWidgetInspectorOverrideCallback);
|
valueListenableBuilderWidget.valueListenable.addListener(debugShowWidgetInspectorOverrideCallback);
|
||||||
|
|
||||||
service.rebuildCount = 0;
|
service.rebuildCount = 0;
|
||||||
|
@ -4155,7 +4155,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
||||||
),
|
),
|
||||||
equals('true'),
|
equals('true'),
|
||||||
);
|
);
|
||||||
expect(WidgetsApp.debugShowWidgetInspectorOverride, isTrue);
|
expect(WidgetsBinding.instance.debugShowWidgetInspectorOverride, isTrue);
|
||||||
expect(extensionChangedEvents.length, equals(1));
|
expect(extensionChangedEvents.length, equals(1));
|
||||||
expect(service.rebuildCount, equals(0)); // Should not be force rebuilt.
|
expect(service.rebuildCount, equals(0)); // Should not be force rebuilt.
|
||||||
expect(debugShowChangeCounter, equals(1));
|
expect(debugShowChangeCounter, equals(1));
|
||||||
|
@ -4195,7 +4195,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService {
|
||||||
expect(extensionChangedEvents.length, equals(3));
|
expect(extensionChangedEvents.length, equals(3));
|
||||||
expect(service.rebuildCount, equals(0)); // Should not be force rebuilt.
|
expect(service.rebuildCount, equals(0)); // Should not be force rebuilt.
|
||||||
expect(debugShowChangeCounter, equals(2));
|
expect(debugShowChangeCounter, equals(2));
|
||||||
expect(WidgetsApp.debugShowWidgetInspectorOverride, isFalse);
|
expect(WidgetsBinding.instance.debugShowWidgetInspectorOverride, isFalse);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('ext.flutter.inspector.screenshot', (WidgetTester tester) async {
|
testWidgets('ext.flutter.inspector.screenshot', (WidgetTester tester) async {
|
||||||
|
|
|
@ -1174,6 +1174,8 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
|
||||||
keyEventManager.clearState();
|
keyEventManager.clearState();
|
||||||
// ignore: invalid_use_of_visible_for_testing_member
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
RendererBinding.instance.initMouseTracker();
|
RendererBinding.instance.initMouseTracker();
|
||||||
|
|
||||||
|
assert(ServicesBinding.instance == WidgetsBinding.instance);
|
||||||
// ignore: invalid_use_of_visible_for_testing_member
|
// ignore: invalid_use_of_visible_for_testing_member
|
||||||
ServicesBinding.instance.resetInternalState();
|
ServicesBinding.instance.resetInternalState();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue