-
Notifications
You must be signed in to change notification settings - Fork 29.7k
[ Widget Preview ] Forward Widget Inspector navigation events via DTD #176218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
With the assumption that IDEs will not create a debug session for the widget previewer, the widget inspector's source navigation functionality won't function as there's no IDE to listen to `navigate` events sent via `postEvent`. This change overrides some widget inspector behavior to allow for navigating to source locations via the DTD Editor service instead of relying on the VM service's `postEvent`. This change also makes some minor changes to the diagnostic properties and descriptions displayed within the inspector to display group and custom preview annotation details. Towards #166423
There was a problem hiding this 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 introduces a mechanism to forward widget inspector navigation events through the Dart Tooling Daemon (DTD), which is a great improvement for the widget previewer's developer experience, especially in IDEs without a debug session. The changes are well-structured, propagating the necessary source location information through the analysis and code generation phases to the scaffolded application. The introduction of PreviewWidgetElement and the custom _WidgetPreviewScaffoldInspectorService is a clean approach to intercept and handle navigation.
I've found one critical issue in the navigation event handling logic that could lead to a runtime crash, and I've provided a suggestion to fix it. Otherwise, the changes look solid and the new test case for inspector navigation is a valuable addition.
...tools/templates/widget_preview_scaffold/lib/src/widget_preview_scaffold_controller.dart.tmpl
Outdated
Show resolved
Hide resolved
How sound is this assumption? (I asked because of the question below, and that we are already auto-attaching to the preview on Firebase Studio, so I don't think the idea of attaching to it is completely crazy - but I don't know what's already been thought about/discussed).
Which widget inspector do we mean here? The one that's embedded in the sidebar in Dart-Code is already quite tightly tied to a debug session, so if we're planning to connect that to the preview (and not have the preview be a debug session) then we might need to change some of these assumptions anyway. (that's not to say it's not a good idea to switch this to DTD anyway, but it would be useful for me to better understand the end goals here) Edit: To capture some offline discussion:
We can't have a full debug session against the widget preview, because there's no ability to use the Chrome debug port or Dart debug extension, so actually it probably does not make sense to try and connect up a normal IDE debug session here. |
DanTup
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not terribly familiar with the widget inspector service code so I'll let you choose whether to wait for Elliot's review, but LGTM. I did add some minor nits, but nothing I think is necessary.
packages/flutter_tools/lib/src/widget_preview/preview_details.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/templates/widget_preview_scaffold/lib/src/widget_preview.dart.tmpl
Show resolved
Hide resolved
...tools/templates/widget_preview_scaffold/lib/src/widget_preview_scaffold_controller.dart.tmpl
Show resolved
Hide resolved
...tools/test/widget_preview_scaffold.shard/widget_preview_scaffold/lib/src/widget_preview.dart
Show resolved
Hide resolved
...widget_preview_scaffold.shard/widget_preview_scaffold/test/filter_by_selected_file_test.dart
Outdated
Show resolved
Hide resolved
| column: previewData.column, | ||
| ); | ||
| } | ||
| final result = super.setSelection(object, groupName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little awkward - would it be simpler to skip this call and just directly call super.postEvent() with this location instead? Or if we still need the other base code (setting the selection), what about making setSelection take an optional Location?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's definitely awkward, but super.setSelection needs to be called as there's a lot of other state that's updated as the result of a selection.
This code is called via a service extension, and DevTools doesn't know that there's anything special about the PreviewWidget, so we need to keep this logic contained within the previewer.
| line: -1, | ||
| column: -1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bkonyi nit: there are a couple more of these 😄
|
autosubmit label was removed for flutter/flutter/176218, because - The status or check suite Mac build_ios_framework_module_test has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/flutter/176218, because - The status or check suite Mac build_ios_framework_module_test has failed. Please fix the issues identified (or deflake) before re-applying this label. |
…10160) Manual roll requested by [email protected] flutter/flutter@c9608e2...7811e89 2025-10-01 [email protected] Migrate to `WidgetStateTextStyle` (flutter/flutter#176330) 2025-10-01 [email protected] Migrate to `WidgetStateOutlinedBorder` (flutter/flutter#176270) 2025-10-01 [email protected] [win32] Runloop should use high resolution timer and avoid deadlock (flutter/flutter#176023) 2025-10-01 [email protected] Roll Packages from 287739d to 321a584 (3 revisions) (flutter/flutter#176357) 2025-10-01 [email protected] Add SwiftUI support for UIScene migration (flutter/flutter#176230) 2025-10-01 [email protected] Roll Skia from ecaff95f51aa to c44a36470d07 (4 revisions) (flutter/flutter#176336) 2025-10-01 [email protected] [native assets] Enable build hooks and code assets on stable (flutter/flutter#176285) 2025-10-01 [email protected] [native assets] Roll dependencies (flutter/flutter#176287) 2025-10-01 [email protected] Roll Dart SDK from 527333cfe4cf to 8ffec1435cf3 (1 revision) (flutter/flutter#176334) 2025-10-01 [email protected] Roll Skia from 6998b06397c5 to ecaff95f51aa (1 revision) (flutter/flutter#176333) 2025-10-01 [email protected] Update description in _LastFinderMixin to properly describe finding last (flutter/flutter#174232) 2025-10-01 [email protected] Roll Skia from b242cc09488d to 6998b06397c5 (2 revisions) (flutter/flutter#176331) 2025-10-01 [email protected] Roll Dart SDK from af31d2637b6b to 527333cfe4cf (17 revisions) (flutter/flutter#176325) 2025-10-01 [email protected] Stop using deprecated analyzer 7.x.y APIs. (flutter/flutter#176242) 2025-10-01 [email protected] Fix docs referencing deprecated radio properties (flutter/flutter#176244) 2025-09-30 [email protected] Roll Skia from bb3b6bd4be0d to b242cc09488d (22 revisions) (flutter/flutter#176320) 2025-09-30 [email protected] Roll Fuchsia Linux SDK from rcOl0yxJb4znJ903Y... to 1Ai6VL4vb_GdGnWhg... (flutter/flutter#176315) 2025-09-30 [email protected] Adds dart ui API for setting application level locale (flutter/flutter#175100) 2025-09-30 [email protected] replace `onPop` usage with `onPopWithResult` in `navigation_bar.2.dart ` (flutter/flutter#174841) 2025-09-30 [email protected] [ Widget Preview ] Forward Widget Inspector navigation events via DTD (flutter/flutter#176218) 2025-09-30 [email protected] Add verbose logs to module_uiscene_test_ios (flutter/flutter#176306) 2025-09-30 [email protected] Web semantics: Fix email field selection/cursor by using type="text" + inputmode="email" (flutter/flutter#175876) 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
…flutter#176218) With the assumption that IDEs will not create a debug session for the widget previewer, the widget inspector's source navigation functionality won't function as there's no IDE to listen to `navigate` events sent via `postEvent`. This change overrides some widget inspector behavior to allow for navigating to source locations via the DTD Editor service instead of relying on the VM service's `postEvent`. This change also makes some minor changes to the diagnostic properties and descriptions displayed within the inspector to display group and custom preview annotation details. Towards flutter#166423
…flutter#176218) With the assumption that IDEs will not create a debug session for the widget previewer, the widget inspector's source navigation functionality won't function as there's no IDE to listen to `navigate` events sent via `postEvent`. This change overrides some widget inspector behavior to allow for navigating to source locations via the DTD Editor service instead of relying on the VM service's `postEvent`. This change also makes some minor changes to the diagnostic properties and descriptions displayed within the inspector to display group and custom preview annotation details. Towards flutter#166423
With the assumption that IDEs will not create a debug session for the widget previewer, the widget inspector's source navigation functionality won't function as there's no IDE to listen to
navigateevents sent viapostEvent.This change overrides some widget inspector behavior to allow for navigating to source locations via the DTD Editor service instead of relying on the VM service's
postEvent.This change also makes some minor changes to the diagnostic properties and descriptions displayed within the inspector to display group and custom preview annotation details.
Towards #166423