Skip to content

Fix widget inspector control layout and add safe area regression test#180789

Merged
elliette merged 14 commits intoflutter:masterfrom
gktirkha:bugfix/widget-inspector-view-padding
Mar 18, 2026
Merged

Fix widget inspector control layout and add safe area regression test#180789
elliette merged 14 commits intoflutter:masterfrom
gktirkha:bugfix/widget-inspector-view-padding

Conversation

@gktirkha
Copy link
Contributor

@gktirkha gktirkha commented Jan 10, 2026

Description

This PR fixes Widget Inspector controls not respecting system safe area insets.

Previously, the inspector control buttons were positioned without accounting for system UI insets (such as gesture navigation bars), which could cause them to overlap or be partially obscured by system UI.

This change updates the Widget Inspector control layout to respect MediaQuery.viewPadding when positioning the controls. Importantly, the safe area handling is scoped only to the inspector controls themselves, so the previewed application and inspector selection overlay continue to occupy the full available screen and remain selectable in unsafe areas.

A regression test is added to ensure preview content is not inset when viewPadding is present.

Issues fixed

  • Fixes Widget Inspector controls overlapping system UI due to missing safe area handling.
  • Ensures preview content is not inset when inspector controls respect system safe areas.

(No existing issue was filed; this was identified during review. Happy to link one if preferred.)

Tests

  • Added a widget test verifying that preview content is not inset when MediaQuery.viewPadding is applied.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///) where appropriate.
  • I added new tests to check the change I am making.
  • I followed the [breaking change policy] (no breaking changes).
  • All existing and new tests are passing.

Beofre Fix

533829007-5aba7be7-e8bd-47f4-9d64-38e1ab1a0c6b

After Fix

Screenshot_1768012272

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Jan 10, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes an issue where the Widget Inspector controls could overlap with system UI by not respecting safe area insets. The change adjusts the bottom padding of the inspector controls using MediaQuery.viewPaddingOf(context).bottom. A regression test is also added to ensure that the application content being previewed is not incorrectly inset, which is a good safeguard against regressions. My feedback includes a suggestion to add a direct test for the control's position to fully cover the fix.

@elliette
Copy link
Member

Hi @gktirkha - thank you for opening a PR! To make this easier to review, could you file an issue in the Flutter repo that describes this issue (along with steps on how to reproduce) and link to it in this PR. Thank you!

@gktirkha
Copy link
Contributor Author

gktirkha commented Jan 14, 2026

Hi @gktirkha - thank you for opening a PR! To make this easier to review, could you file an issue in the Flutter repo that describes this issue (along with steps on how to reproduce) and link to it in this PR. Thank you!

Sure @justinmc , Here it is

#180956

@gktirkha gktirkha requested a review from elliette January 23, 2026 18:06
Copy link
Member

@elliette elliette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay! This is looking good. Just a couple more requests. Thank you!

Copy link
Member

@elliette elliette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM once tests are passing. Thank you!

@gktirkha gktirkha force-pushed the bugfix/widget-inspector-view-padding branch from f22ee11 to 7171cbd Compare January 29, 2026 03:51
@gktirkha gktirkha force-pushed the bugfix/widget-inspector-view-padding branch 2 times, most recently from faf6ae6 to 1af656c Compare February 1, 2026 10:52
@gktirkha gktirkha force-pushed the bugfix/widget-inspector-view-padding branch from 1af656c to a561882 Compare February 1, 2026 10:56
@gktirkha
Copy link
Contributor Author

gktirkha commented Feb 7, 2026

Hi @elliette, just checking in to see if there are any updates on this PR. Thanks for taking a look!

@elliette
Copy link
Member

elliette commented Feb 9, 2026

Hi @elliette, just checking in to see if there are any updates on this PR. Thanks for taking a look!

Hi! Do you mind looking into the test failures to see if they are related to this PR? It looks the failing tests are the widget tests. Merging in the main branch might further help determine whether the test failures are due to this PR or not. Thanks!

 Command: ../../bin/flutter test --reporter=expanded --file-reporter=json:/b/s/w/ir/x/t/metrics_1769943602511512.json --test-randomize-ordering-seed=20260201 --fatal-warnings --track-widget-creation test/widgets/
║ Command exited with exit code 1 but expected zero exit code.
║ Working directory: /b/s/w/ir/x/w/flutter/packages/flutter

@gktirkha
Copy link
Contributor Author

gktirkha commented Feb 10, 2026

Hi @elliette, just checking in to see if there are any updates on this PR. Thanks for taking a look!

Hi! Do you mind looking into the test failures to see if they are related to this PR? It looks the failing tests are the widget tests. Merging in the main branch might further help determine whether the test failures are due to this PR or not. Thanks!

 Command: ../../bin/flutter test --reporter=expanded --file-reporter=json:/b/s/w/ir/x/t/metrics_1769943602511512.json --test-randomize-ordering-seed=20260201 --fatal-warnings --track-widget-creation test/widgets/
║ Command exited with exit code 1 but expected zero exit code.
║ Working directory: /b/s/w/ir/x/w/flutter/packages/flutter

I Don't think that it is related

bin/flutter test --reporter=expanded --file-reporter=json:/b/s/w/ir/x/t/metrics_1769943602511512.json --test-randomize-ordering-seed=20260201 --fatal-warnings --track-widget-creation test/widgets/
Resolving dependencies...
The current Flutter SDK version is 0.0.0-unknown.

Because _flutter_packages depends on webview_flutter_wkwebview 3.23.5 which requires Flutter SDK version >=3.35.0, version solving failed.
Failed to update packages.
Screenshot 2026-02-10 at 18 00 36

but if I do use flutter from main branch (system flutter)

Resolving dependencies...
Downloading packages...
  _fe_analyzer_shared 92.0.0 (94.0.0 available)
  adaptive_breakpoints 0.1.7 (discontinued)
  analyzer 9.0.0 (10.0.2 available)
  archive 3.6.1 (4.0.7 available)
  dart_style 3.1.3 (3.1.5 available)
  device_info 2.0.3 (discontinued replaced by device_info_plus)
  gcloud 0.8.19 (0.9.0 available)
  google_fonts 6.3.3 (8.0.1 available)
  google_mobile_ads 5.1.0 (7.0.0 available)
  googleapis 14.0.0 (16.0.0 available)
  hooks 1.0.0 (1.0.1 available)
  isolate 2.1.1 (discontinued)
  js 0.7.2 (discontinued)
  json_annotation 4.9.0 (4.10.0 available)
  lints 6.0.0 (6.1.0 available)
  meta 1.18.0 (1.18.1 available)
  objective_c 9.2.3 (9.3.0 available)
  pedantic 1.11.1 (discontinued replaced by lints)
  source_span 1.10.1 (1.10.2 available)
  url_launcher_ios 6.3.6 (6.4.0 available)
  video_player_avfoundation 2.8.10 (2.9.1 available)
  webview_flutter 4.9.0 (4.13.1 available)
  webview_flutter_android 3.16.9 (4.10.11 available)
  webview_flutter_wkwebview 3.23.5 (3.23.6 available)
Got dependencies!
5 packages are discontinued.
19 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.
Shuffling test order with --test-randomize-ordering-seed=20260201
Creation failed, path = '/b' (OS Error: Read-only file system, errno = 30)
dart:io                                                             _File.createSync
package:test_core/src/runner.dart 87:32                             new Runner.<fn>.createFileReporter
package:test_core/src/runner.dart 99:15                             new Runner.<fn>
dart:async                                                          runZoned
package:test_core/src/runner/configuration.dart 865:7               Configuration.asCurrent
package:test_core/src/runner.dart 76:50                             new Runner
package:test_core/src/executable.dart 149:14                        _execute
package:test_core/src/executable.dart 38:9                          main
package:flutter_tools/src/test/test_wrapper.dart 31:16              _DefaultTestWrapper.main
package:flutter_tools/src/test/runner.dart 187:25                   FlutterTestRunner.runTests
package:flutter_tools/src/commands/test.dart 662:33                 TestCommand.runCommand
package:flutter_tools/src/runner/flutter_command.dart 1559:27       FlutterCommand.run.<fn>
package:flutter_tools/src/base/context.dart 154:19                  AppContext.run.<fn>
package:args/command_runner.dart 212:13                             CommandRunner.runCommand
package:flutter_tools/src/runner/flutter_command_runner.dart 487:9  FlutterCommandRunner.runCommand.<fn>
package:flutter_tools/src/base/context.dart 154:19                  AppContext.run.<fn>
package:flutter_tools/src/runner/flutter_command_runner.dart 422:5  FlutterCommandRunner.runCommand
package:flutter_tools/runner.dart 104:11                            run.<fn>.<fn>
package:flutter_tools/src/base/context.dart 154:19                  AppContext.run.<fn>
package:flutter_tools/executable.dart 103:3                         main

This is an unexpected error. Please file an issue at http://github.com/dart-lang/test
with the stack trace and instructions for reproducing the error.

@elliette
Copy link
Member

Tree is currently broken. Please do not merge this PR unless it contains a fix for the tree.

Thank you! Looks like the tree is currently broken. Let's wait for that to resolve and then make sure the tests are passing. Sorry for wait!

@gktirkha
Copy link
Contributor Author

gktirkha commented Mar 3, 2026

Here is the failing test log:

04:40 +5305 ~17: /b/s/w/ir/x/w/flutter/packages/flutter/test/widgets/widget_inspector_test.dart: Multiple widget inspectors
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following _TypeError was thrown running a test:
Null check operator used on a null value

When the exception was thrown, this was the stack:
#0      _TestWidgetInspectorService.runTests.<anonymous closure> (file:///b/s/w/ir/x/w/flutter/packages/flutter/test/widgets/widget_inspector_test.dart:909:72)
<asynchronous suspension>
#1      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:192:15)
<asynchronous suspension>
#2      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:1800:5)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)

The test description was:
  Multiple widget inspectors
════════════════════════════════════════════════════════════════════════════════════════════════════
04:40 +5305 ~17 -1: /b/s/w/ir/x/w/flutter/packages/flutter/test/widgets/parent_data_test.dart: ParentDataWidget control test
04:40 +5305 ~17 -1: /b/s/w/ir/x/w/flutter/packages/flutter/test/widgets/widget_inspector_test.dart: Multiple widget inspectors [E]
  Test failed. See exception logs above.
  The test description was: Multiple widget inspectors

did this,
_WidgetInspectorButtonGroupState.build — use math.max to preserve minimum bottom margin

// Before
final double bottomPadding = MediaQuery.viewPaddingOf(context).bottom;

// After
final double bottomPadding = math.max(_kExitWidgetSelectionButtonMargin,MediaQuery.viewPaddingOf(context).bottom);

Using viewPadding.bottom alone breaks on devices/environments with no bottom safe area inset (Android, older iPhones, tests) where it returns 0.

@gktirkha gktirkha requested a review from elliette March 3, 2026 05:02
@gktirkha
Copy link
Contributor Author

gktirkha commented Mar 3, 2026

hi @elliette

I Believe all widgets tests related to pr have passed, let me know if i can do anything regarding failed test cases

@elliette
Copy link
Member

elliette commented Mar 6, 2026

I Believe all widgets tests related to pr have passed, let me know if i can do anything regarding failed test cases

Hi @gktirkha - it looks like the widget_inspector needs to be formatted:

Found 1 Dart file which was formatted incorrectly.
To fix, run `dart format packages/flutter/lib/src/widgets/widget_inspector.dart`

@gktirkha
Copy link
Contributor Author

gktirkha commented Mar 7, 2026

I Believe all widgets tests related to pr have passed, let me know if i can do anything regarding failed test cases

Hi @gktirkha - it looks like the widget_inspector needs to be formatted:

Found 1 Dart file which was formatted incorrectly.
To fix, run `dart format packages/flutter/lib/src/widgets/widget_inspector.dart`

Oops!, forgot that
Fixed it

Copy link
Member

@elliette elliette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@elliette elliette added this pull request to the merge queue Mar 17, 2026
Merged via the queue into flutter:master with commit 5e1be56 Mar 18, 2026
72 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Mar 19, 2026
flutter/flutter@d117642...dd64978

2026-03-18 [email protected] Roll Skia from 2fb5fa71eb12 to f0a13e5efbad (2 revisions) (flutter/flutter#183830)
2026-03-18 [email protected] Roll Skia from ae3d36cb9e29 to 2fb5fa71eb12 (3 revisions) (flutter/flutter#183823)
2026-03-18 [email protected] Linux reuse sibling (flutter/flutter#183653)
2026-03-18 [email protected] Roll Skia from 84a180a1fa80 to ae3d36cb9e29 (4 revisions) (flutter/flutter#183812)
2026-03-18 [email protected] fix(web): handle asynchronously disposed platform views (flutter/flutter#183666)
2026-03-17 [email protected] (Test cross-imports) Remove legacy Material import from sliver_constraints_test (flutter/flutter#183351)
2026-03-17 [email protected] Fix Android Studio pluginsPath when version is unknown (do not use 0.0) (flutter/flutter#182681)
2026-03-17 [email protected] Fixes animation glitch into bottom sheet (flutter/flutter#183303)
2026-03-17 [email protected] Handle#6537 second grouped test (flutter/flutter#182529)
2026-03-17 [email protected] Add a Clarification for the docs of suggestionsBuilder of SearchAnchor (flutter/flutter#183106)
2026-03-17 [email protected] Remove obsolete null checks from style guide (flutter/flutter#181703)
2026-03-17 [email protected] [Impeller] Do not delete the GL object in a HandleGLES if the handle has a cleanup callback (flutter/flutter#183561)
2026-03-17 [email protected] Encode source file patches as UTF-8 in the code formatter script (flutter/flutter#183761)
2026-03-17 [email protected] Fix widget inspector control layout and add safe area regression test (flutter/flutter#180789)
2026-03-17 [email protected] Reland "[Android] Add mechanism for setting Android engine flags via Android manifest (take 2)" (flutter/flutter#182522)
2026-03-17 [email protected] fix(web): fix crash in Skwasm when transferring non-transferable texture sources (flutter/flutter#183799)
2026-03-17 [email protected] Roll Skia from dba893a44d7a to 84a180a1fa80 (7 revisions) (flutter/flutter#183803)
2026-03-17 [email protected] Framework: Improve DropdownButton selectedItemBuilder assertion (flutter/flutter#183732)
2026-03-17 [email protected] Add mainAxisAlignment to NavigationRail (flutter/flutter#183514)
2026-03-17 [email protected] Update android triage process to not look at unassigned p1s every week (flutter/flutter#183805)
2026-03-17 [email protected] Adds macos impeller new gallery transition perf test. (flutter/flutter#183802)
2026-03-17 [email protected] fix(web_ui): move prepareToDraw after raster to improve concurrency and stability (flutter/flutter#183791)
2026-03-17 [email protected] [build] Generate debug info for assembly. (flutter/flutter#183425)
2026-03-17 [email protected] [web] Fix occasional failure to find Chrome tab (flutter/flutter#183737)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants