Skip to content

Update the file read of the Flutter version file to check for the new format #8466

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
merged 1 commit into from
Aug 16, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Removed

- The Flutter version is now read from the file ./bin/cache/flutter.version.json, required in Flutter 3.33+ (#8465)

### Changed

- Resolved a "Slow operations are prohibited on EDT" exception on Flutter Project creation (#8446, #8447, #8448)
Expand Down
46 changes: 39 additions & 7 deletions src/io/flutter/sdk/FlutterSdkVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
package io.flutter.sdk;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.intellij.openapi.util.Version;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Objects;

public final class FlutterSdkVersion implements Comparable<FlutterSdkVersion> {
Expand Down Expand Up @@ -94,6 +97,14 @@ public FlutterSdkVersion(@Nullable String versionString) {

@NotNull
public static FlutterSdkVersion readFromSdk(@NotNull VirtualFile sdkHome) {
// First check for the file at <sdkHome>/bin/cache/flutter.version.json
// https://github.com/flutter/flutter-intellij/issues/8465
final VirtualFile versionFile = sdkHome.findFileByRelativePath("bin/cache/flutter.version.json");
if (versionFile != null && versionFile.exists() && !versionFile.isDirectory()) {
return readFromFile(versionFile);
}

// Fallback to the old location at <sdkHome>/version
return readFromFile(sdkHome.findChild("version"));
}

Expand All @@ -109,14 +120,33 @@ private static FlutterSdkVersion readFromFile(@Nullable VirtualFile file) {
private static String readVersionString(@NotNull VirtualFile file) {
try {
final String data = new String(file.contentsToByteArray(), StandardCharsets.UTF_8);
for (String line : data.split("\n")) {
line = line.trim();

if (line.isEmpty() || line.startsWith("#")) {
continue;
// Check if the content is a JSON object.
// This tests to see if it is of the format provided by <sdkHome>/bin/cache/flutter.version.json files
// https://github.com/flutter/flutter-intellij/issues/8465
if (data.trim().startsWith("{")) {
try {
final Map<String, Object> json = new Gson().fromJson(data, new TypeToken<Map<String, Object>>() {
}.getType());
if (json != null && json.containsKey("frameworkVersion")) {
System.out.println("FlutterSdkVersion.readVersionString NEW " + json.get("frameworkVersion"));
return (String)json.get("frameworkVersion");
}
}
catch (com.google.gson.JsonSyntaxException e) {
return null;
}
}
else {
// Otherwise, handle the old plain text format.
for (String line : data.split("\n")) {
line = line.trim();

if (line.isEmpty() || line.startsWith("#")) {
continue;
}
return line;
}

return line;
}
return null;
}
Expand Down Expand Up @@ -145,7 +175,9 @@ public boolean canUseDevToolsMultiEmbed() {
return supportsVersion(MIN_SUPPORTS_DEVTOOLS_MULTI_EMBED);
}

/** @noinspection BooleanMethodIsAlwaysInverted*/
/**
* @noinspection BooleanMethodIsAlwaysInverted
*/
public boolean canUseDtd() {
return supportsVersion(MIN_SUPPORTS_DTD);
}
Expand Down