diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index 73110065d3..2463e3bbec 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -960,7 +960,15 @@ mixin WidgetInspectorService { /// Structured errors provide semantic information that can be used by IDEs /// to enhance the display of errors with rich formatting. bool isStructuredErrorsEnabled() { - return const bool.fromEnvironment('flutter.inspector.structuredErrors'); + // This is a debug mode only feature and will default to false for + // profile mode. + bool enabled = false; + assert(() { + // TODO(kenz): add support for structured errors on the web. + enabled = const bool.fromEnvironment('flutter.inspector.structuredErrors', defaultValue: !kIsWeb); + return true; + }()); + return enabled; } /// Called to register service extensions. diff --git a/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart b/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart index 27b12e3daa..c52988a754 100644 --- a/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_structure_error_test.dart @@ -56,14 +56,14 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect final StructureErrorTestWidgetInspectorService service = StructureErrorTestWidgetInspectorService(); WidgetInspectorService.instance = service; - test('ext.flutter.inspector.structuredErrors still report error to original on error', () async { + test('ext.flutter.inspector.structuredErrors reports error to _structuredExceptionHandler on error', () async { final FlutterExceptionHandler? oldHandler = FlutterError.onError; - late FlutterErrorDetails actualError; + bool usingNewHandler = false; // Creates a spy onError. This spy needs to be set before widgets binding // initializes. FlutterError.onError = (FlutterErrorDetails details) { - actualError = details; + usingNewHandler = true; }; WidgetsFlutterBinding.ensureInitialized(); @@ -81,8 +81,13 @@ class StructureErrorTestWidgetInspectorService extends Object with WidgetInspect ); FlutterError.reportError(expectedError); - // Validates the spy still received an error. - expect(actualError, expectedError); + // For non-web apps, this validates the new handler did not receive an + // error because `FlutterError.onError` was set to + // `WidgetInspectorService._structuredExceptionHandler` when service + // extensions were initialized. For web apps, the new handler should + // have received an error because structured errors are disabled by + // default on the web. + expect(usingNewHandler, equals(kIsWeb)); } finally { FlutterError.onError = oldHandler; }