Repository navigation
Add a platform override dropdown to the Inspector toolbar - #10061
Aadeesh-01 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new PlatformOverrideDropdown widget to the DevTools Inspector toolbar, allowing users to override the target platform of a connected Flutter app. It also adds 'windows' to the supported platforms and updates the relevant tests, release notes, and changelogs. The feedback suggests aligning the implementation with the DevTools Style Guide by using MultiValueListenableBuilder instead of nested ValueListenableBuilders, and replacing unawaited with safeUnawaited for fire-and-forget futures.
| return ValueListenableBuilder<bool>( | ||
| valueListenable: extensionManager.hasServiceExtension(extensionName), | ||
| builder: (context, available, _) { | ||
| if (!available) return const SizedBox.shrink(); | ||
| return ValueListenableBuilder<ServiceExtensionState>( | ||
| valueListenable: extensionManager.getServiceExtensionState( | ||
| extensionName, | ||
| ), | ||
| builder: (context, state, _) { | ||
| // The value is null until DevTools has read it from the app. | ||
| final current = state.value as String?; | ||
| return AnalyticsDropDownButton<String>( | ||
| key: dropdownKey, | ||
| gaScreen: gac.inspector, | ||
| gaDropDownId: gac.togglePlatform, | ||
| message: togglePlatformMode.tooltip, | ||
| isDense: true, | ||
| value: current, | ||
| items: [ | ||
| for (final platform in _platformsToShow(current)) | ||
| _buildMenuItem(platform), | ||
| ], | ||
| onChanged: _onPlatformChanged, | ||
| ); | ||
| }, | ||
| ); | ||
| }, | ||
| ); |
There was a problem hiding this comment.
[CONCERN] Use the MultiValueListenableBuilder helper instead of nesting ValueListenableBuilders, as recommended by the DevTools Style Guide.
return MultiValueListenableBuilder(
listenables: [
extensionManager.hasServiceExtension(extensionName),
extensionManager.getServiceExtensionState(extensionName),
],
builder: (context, values, _) {
final available = values[0] as bool;
if (!available) return const SizedBox.shrink();
final state = values[1] as ServiceExtensionState;
// The value is null until DevTools has read it from the app.
final current = state.value as String?;
return AnalyticsDropDownButton<String>(
key: dropdownKey,
gaScreen: gac.inspector,
gaDropDownId: gac.togglePlatform,
message: togglePlatformMode.tooltip,
isDense: true,
value: current,
items: [
for (final platform in _platformsToShow(current))
_buildMenuItem(platform),
],
onChanged: _onPlatformChanged,
);
},
);References
- Prefer MultiValueListenableBuilder instead of nested ValueListenableBuilders. (link)
| unawaited( | ||
| serviceConnection.serviceManager.serviceExtensionManager | ||
| .setServiceExtensionState( | ||
| togglePlatformMode.extension, | ||
| enabled: true, | ||
| value: platform, | ||
| ), | ||
| ); |
There was a problem hiding this comment.
[CONCERN] Use safeUnawaited instead of unawaited for fire-and-forget futures, as recommended by the DevTools Style Guide.
safeUnawaited(
serviceConnection.serviceManager.serviceExtensionManager
.setServiceExtensionState(
togglePlatformMode.extension,
enabled: true,
value: platform,
),
);References
- Prefer safeUnawaited(...) for fire-and-forget futures. (link)
Fixes #2780
Adds a dropdown to the Flutter Inspector toolbar that overrides the target platform of the connected app, using the existing
ext.flutter.platformOverrideservice extension (togglePlatformMode). This brings back the platform switch that the IntelliJ Inspector had.Changes
PlatformOverrideDropdowninservice_extension_widgets.dart, built onAnalyticsDropDownButton(dense, with an icon and name for each platform).getServiceExtensionStateand sets it withsetServiceExtensionState, so it stays in sync when the app changes the platform itself.hasServiceExtensionis false, for example in profile or release mode.TogglePlatformSelectordid.DropdownButtondoes not throw.InspectorServiceExtensionButtonGroup, before the overlay buttons.windowstotogglePlatformModevalues indevtools_app_shared, with a CHANGELOG entry. Without it, after switching a Windows app to another platform there was no way to switch back.iOS,Android,macOS, … because the icon and tooltip already give context. This also fixesMacOStomacOS.TODO(#2780)andignore: unused-codecomments ontogglePlatformMode.Screenshots
Questions for reviewers
ServiceExtensionManagertreats multi-value extensions as enabled, so a "Default" entry would not stay selected. Picking your own platform works as a reset. I'm happy to add a default option if you have an approach you prefer.ServiceExtensionSelector/TogglePlatformSelectorblock inservice_extension_widgets.dart. This PR is the Flutter version that its TODO asks for, so I can delete it here if you'd like.Tests
test/service/service_extension_widgets_test.dart: switching the platform calls the extension with the new value; Windows is listed and Fuchsia is not; an unknown platform reported by the app is listed; the dropdown is hidden when the extension is unavailable.test/screens/inspector/inspector_screen_test.dart: the dropdown appears in the Inspector toolbar.Pre-launch Checklist
General checklist
///).Issues checklist
contributions-welcomeorgood-first-issuelabel.contributions-welcomeorgood-first-issuelabel. I understand this means my PR might take longer to be reviewed.Tests checklist
AI-tooling checklist
Feature-change checklist
release-notes-not-requiredlabel or left a comment requesting the label be added.packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md.If you need help, consider asking for help on Discord.
🤖 Generated with Claude Code