Skip to content

Commit 99e1f4b

Browse files
committed
WIP
This fixes the issue of DevTools windows not appearing (#8029). Currently, this only would resolve the issue for Deep Links.
1 parent 1a604dd commit 99e1f4b

File tree

3 files changed

+85
-8
lines changed

3 files changed

+85
-8
lines changed

flutter-idea/src/io/flutter/deeplinks/DeepLinksViewFactory.java

+52-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.flutter.sdk.FlutterSdkVersion;
1919
import io.flutter.utils.AsyncUtils;
2020
import io.flutter.utils.OpenApiUtils;
21+
import io.flutter.view.ViewUtils;
2122
import kotlin.coroutines.Continuation;
2223
import org.jetbrains.annotations.NotNull;
2324

@@ -27,18 +28,63 @@
2728
public class DeepLinksViewFactory implements ToolWindowFactory {
2829
@NotNull private static String TOOL_WINDOW_ID = "Flutter Deep Links";
2930

31+
@NotNull
32+
private final ViewUtils viewUtils = new ViewUtils();
33+
3034
@Override
3135
public Object isApplicableAsync(@NotNull Project project, @NotNull Continuation<? super Boolean> $completion) {
32-
FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
33-
FlutterSdkVersion sdkVersion = sdk == null ? null : sdk.getVersion();
34-
return sdkVersion != null && sdkVersion.canUseDeepLinksTool();
36+
// Due to https://github.com/flutter/flutter/issues/142521, this always returns true when the
37+
// Flutter IJ plugin is installed.
38+
39+
// The logic which asserts that the Flutter SDK is up to date enough for this particular feature
40+
// is captured in the implementation of createToolWindowContent() below.
41+
42+
return true;
3543
}
3644

3745
@Override
3846
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
39-
FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
40-
FlutterSdkVersion sdkVersion = sdk == null ? null : sdk.getVersion();
47+
final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
48+
final FlutterSdkVersion flutterSdkVersion = flutterSdk == null ? null : flutterSdk.getVersion();
49+
50+
// There are four potential states for the Flutter SDK:
51+
// 1. The Flutter SDK is null (flutterSdk == null) (an SDK path is invalid or not configured)
52+
// 2. The Flutter SDK exists, but version file information is unavailable (flutterSdkVersion == null),
53+
// see https://github.com/flutter/flutter/issues/142521.
54+
// 3. The Flutter SDK exists, and the version file information is available, but this tool is not
55+
// available on the version of the SDK that the user has.
56+
// 4. The Flutter SDK exists with valid version information.
57+
58+
// First case:
59+
if (flutterSdk == null) {
60+
viewUtils.presentLabels(toolWindow, List.of("Set the Flutter SDK path in",
61+
"Settings > Languages & Frameworks > Flutter,",
62+
"and then restart the IDE."));
63+
return;
64+
}
65+
66+
// Second case:
67+
if (flutterSdk.getVersion().fullVersion().equals(FlutterSdkVersion.UNKNOWN_VERSION)) {
68+
viewUtils.presentLabels(toolWindow, List.of("A Flutter SDK was found at the location",
69+
"specified in the settings, however the directory",
70+
"is in an incomplete state. To fix, shut down the IDE,",
71+
"run `flutter doctor` or `flutter --version` in the",
72+
"Flutter SDK directory, and then restart the IDE."));
73+
return;
74+
}
75+
76+
// Third case:
77+
if (!flutterSdkVersion.canUseDeepLinksTool()) {
78+
final String versionText = flutterSdkVersion.fullVersion();
79+
viewUtils.presentLabels(toolWindow, List.of("The version of your Flutter SDK,",
80+
versionText + ",",
81+
"is not recent enough to use this tool.",
82+
"Update the Flutter SDK, `flutter upgrade`,",
83+
"and then restart the IDE."));
84+
return;
85+
}
4186

87+
// Final case:
4288
AsyncUtils.whenCompleteUiThread(
4389
DevToolsService.getInstance(project).getDevToolsInstance(),
4490
(instance, error) -> {
@@ -60,7 +106,7 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
60106
.setDevToolsPort(instance.port())
61107
.setPage("deep-links")
62108
.setEmbed(true)
63-
.setFlutterSdkVersion(sdkVersion)
109+
.setFlutterSdkVersion(flutterSdkVersion)
64110
.setWorkspaceCache(WorkspaceCache.getInstance(project))
65111
.setIdeFeature(DevToolsIdeFeature.TOOL_WINDOW)
66112
.build();

flutter-idea/src/io/flutter/sdk/FlutterSdkVersion.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public final class FlutterSdkVersion implements Comparable<FlutterSdkVersion> {
4949
@NotNull
5050
public static final FlutterSdkVersion MIN_SUPPORTS_PROPERTY_EDITOR = new FlutterSdkVersion("3.32.0-0.1.pre");
5151

52+
@NotNull
53+
public static final String UNKNOWN_VERSION = "unknown version";
54+
5255
@Nullable
5356
private final Version version;
5457
@Nullable
@@ -153,7 +156,7 @@ public boolean isValid() {
153156

154157
@NotNull
155158
public String fullVersion() {
156-
return version == null ? "unknown version" : Objects.requireNonNull(version.toString());
159+
return version == null ? UNKNOWN_VERSION : Objects.requireNonNull(version.toString());
157160
}
158161

159162
/**
@@ -167,7 +170,7 @@ public String getVersionText() {
167170
@Override
168171
@NotNull
169172
public String toString() {
170-
return version == null ? "unknown version" : Objects.requireNonNull(version.toCompactString());
173+
return version == null ? UNKNOWN_VERSION : Objects.requireNonNull(version.toCompactString());
171174
}
172175

173176
@Override

flutter-idea/src/io/flutter/view/ViewUtils.java

+28
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.intellij.util.ui.UIUtil;
1616
import io.flutter.utils.LabelInput;
1717
import io.flutter.utils.OpenApiUtils;
18+
import org.jetbrains.annotations.NotNull;
1819

1920
import javax.swing.*;
2021
import java.awt.*;
@@ -27,6 +28,33 @@ public void presentLabel(ToolWindow toolWindow, String text) {
2728
replacePanelLabel(toolWindow, label);
2829
}
2930

31+
/**
32+
* Displays multiple labels vertically centered in the tool window.
33+
*
34+
* @param toolWindow The target tool window.
35+
* @param labels A list of strings to display as labels.
36+
*/
37+
public void presentLabels(@NotNull ToolWindow toolWindow, @NotNull List<String> labels) {
38+
final JPanel labelsPanel = new JPanel(new GridLayout(0, 1));
39+
labelsPanel.setBorder(JBUI.Borders.empty()); // Use padding on individual labels if needed
40+
41+
for (String text : labels) {
42+
final JBLabel label = new JBLabel(text, SwingConstants.CENTER);
43+
label.setForeground(UIUtil.getLabelDisabledForeground());
44+
// Add padding to each label for spacing
45+
label.setBorder(JBUI.Borders.empty(2, 0));
46+
labelsPanel.add(label);
47+
}
48+
49+
// Use VerticalFlowLayout to center the block of labels vertically
50+
final JPanel centerPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.CENTER));
51+
centerPanel.add(labelsPanel);
52+
53+
replacePanelLabel(toolWindow, centerPanel);
54+
}
55+
56+
57+
3058
public void presentClickableLabel(ToolWindow toolWindow, List<LabelInput> labels) {
3159
final JPanel panel = new JPanel(new GridLayout(0, 1));
3260

0 commit comments

Comments
 (0)