Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🐛 Fix DeviceSelectorAction NoSuchElementException in the toolbar layout #8515

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

Merged
auto-submit merged 4 commits into main from copilot/fix-8494
Sep 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Set the device selector component to opaque during its creation to avoid an unexpected background color (#8471)
- Refactored `DeviceSelectorAction` and add rich icons to different platform devices (#8475)
- Fix DTD freezes when opening projects, and EDT freezes when the theme is changed and opening embedded DevTools (#8477)
- Fix `DeviceSelectorAction` `NoSuchElementException` in the toolbar layout (#8515)

## 87.1.0

Expand Down
2 changes: 2 additions & 0 deletions src/io/flutter/FlutterBundle.properties
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ flutter.io.gettingStarted.IDE.url=https://docs.flutter.dev/tools/android-studio
flutter.io.runAndDebug.url=https://docs.flutter.dev/tools/android-studio#running-and-debugging

devicelist.loading=Loading...
devicelist.noDevices=<no devices>
devicelist.noDeviceSelected=<no device selected>

flutter.pop.frame.action.text=Drop Frame (Flutter)
flutter.pop.frame.action.description=Pop the current frame off the stack
Expand Down
38 changes: 31 additions & 7 deletions src/io/flutter/actions/DeviceSelectorAction.java
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class DeviceSelectorAction extends AnAction implements CustomComponentAct
private static final Key<JBLabel> ICON_LABEL_KEY = Key.create("iconLabel");
private static final Key<JBLabel> TEXT_LABEL_KEY = Key.create("textLabel");
private static final Key<JBLabel> ARROW_LABEL_KEY = Key.create("arrowLabel");
private static final @NotNull Icon DEFAULT_DEVICE_ICON = FlutterIcons.Mobile;
private static final @NotNull Icon DEFAULT_ARROW_ICON = IconUtil.scale(AllIcons.General.ChevronDown, null, 1.2f);

private final List<AnAction> actions = new ArrayList<>();
private final List<Project> knownProjects = Collections.synchronizedList(new ArrayList<>());
Expand Down Expand Up @@ -87,9 +89,9 @@ public void actionPerformed(@NotNull AnActionEvent e) {

@Override
public @NotNull JComponent createCustomComponent(@NotNull Presentation presentation, @NotNull String place) {
final JBLabel iconLabel = new JBLabel(FlutterIcons.Mobile);
final JBLabel iconLabel = new JBLabel(DEFAULT_DEVICE_ICON);
final JBLabel textLabel = new JBLabel();
final JBLabel arrowLabel = new JBLabel(IconUtil.scale(AllIcons.General.ChevronDown, null, 1.2f));
final JBLabel arrowLabel = new JBLabel(DEFAULT_ARROW_ICON);

// Create a wrapper button for hover effects
final JButton button = new JButton() {
Expand Down Expand Up @@ -119,17 +121,39 @@ public Dimension getPreferredSize() {
width += icon.getIconWidth();
height = Math.max(height, icon.getIconHeight());
}
else {
// Fallback: use the default mobile icon size when the component is not fully initialized
final Icon defaultIcon = DEFAULT_DEVICE_ICON;
width += defaultIcon.getIconWidth();
height = Math.max(height, defaultIcon.getIconHeight());
}

final @Nullable FontMetrics fm;
final @NotNull String textLabelText;
if (textLabel instanceof JBLabel label && label.getText() instanceof String text && !text.isEmpty()) {
final FontMetrics fm = label.getFontMetrics(label.getFont());
width += Objects.requireNonNull(fm).stringWidth(text);
fm = label.getFontMetrics(label.getFont());
textLabelText = text;
}
else {
// Fallback: estimate width for typical device name length
fm = getFontMetrics(getFont());
textLabelText = FlutterBundle.message("devicelist.noDevices");
}
if (fm != null) {
width += fm.stringWidth(textLabelText);
height = Math.max(height, fm.getHeight());
}

if (arrowLabel instanceof JBLabel label && label.getIcon() instanceof Icon icon) {
width += icon.getIconWidth();
height = Math.max(height, icon.getIconHeight());
}
else {
// Fallback: use the default arrow icon size
final Icon defaultArrow = DEFAULT_ARROW_ICON;
width += defaultArrow.getIconWidth();
height = Math.max(height, defaultArrow.getIconHeight());
}

width += JBUI.scale(24);
height += JBUI.scale(8);
Expand Down Expand Up @@ -278,19 +302,19 @@ public void projectClosing(@NotNull Project project) {
final Collection<FlutterDevice> devices = deviceService.getConnectedDevices();

final String text;
Icon icon = FlutterIcons.Mobile;
Icon icon = DEFAULT_DEVICE_ICON;

if (devices.isEmpty()) {
final boolean isLoading = deviceService.getStatus() == DeviceService.State.LOADING;
if (isLoading) {
text = FlutterBundle.message("devicelist.loading");
}
else {
text = "<no devices>";
text = FlutterBundle.message("devicelist.noDevices");
}
}
else if (selectedDevice == null) {
text = "<no device selected>";
text = FlutterBundle.message("devicelist.noDeviceSelected");
}
else {
text = selectedDevice.presentationName();
Expand Down

AltStyle によって変換されたページ (->オリジナル) /