Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/io/flutter/FlutterBundle.properties
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
31 changes: 27 additions & 4 deletions src/io/flutter/actions/DeviceSelectorAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,44 @@ public Dimension getPreferredSize() {
int width = 0;
int height = JBUI.scale(22);

// Provide fallback values if client properties are not yet set
if (iconLabel instanceof JBLabel label && label.getIcon() instanceof Icon icon) {
width += icon.getIconWidth();
height = Math.max(height, icon.getIconHeight());
}
else if (iconLabel == null) {
// Fallback: use the default mobile icon size when the component is not fully initialized
Icon defaultIcon = FlutterIcons.Mobile;
width += defaultIcon.getIconWidth();
height = Math.max(height, defaultIcon.getIconHeight());
}

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);
height = Math.max(height, fm.getHeight());
if (fm != null) {
width += fm.stringWidth(text);
height = Math.max(height, fm.getHeight());
}
}
else if (textLabel == null) {
// Fallback: estimate width for typical device name length
final FontMetrics fm = getFontMetrics(getFont());
if (fm != null) {
width += fm.stringWidth(FlutterBundle.message("devicelist.noDeviceSelected"));
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 if (arrowLabel == null) {
// Fallback: use the default chevron down icon size
Icon defaultArrow = IconUtil.scale(AllIcons.General.ChevronDown, null, 1.2f);
width += defaultArrow.getIconWidth();
height = Math.max(height, defaultArrow.getIconHeight());
}

width += JBUI.scale(24);
height += JBUI.scale(8);
Expand Down Expand Up @@ -286,11 +309,11 @@ public void projectClosing(@NotNull Project project) {
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