Skip to content

Commit d823dca

Browse files
authored
Write action fix in FlutterModuleUtils (#8490)
This resolves #8480
1 parent 5214718 commit d823dca

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/io/flutter/utils/FlutterModuleUtils.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.execution.RunnerAndConfigurationSettings;
1010
import com.intellij.facet.Facet;
1111
import com.intellij.facet.FacetManager;
12+
import com.intellij.openapi.application.Application;
1213
import com.intellij.openapi.application.ApplicationManager;
1314
import com.intellij.openapi.fileEditor.FileEditor;
1415
import com.intellij.openapi.fileEditor.FileEditorManager;
@@ -383,7 +384,7 @@ public static void setFlutterModuleAndReload(@NotNull Module module, @NotNull Pr
383384
ProjectManager.getInstance().reloadProject(project);
384385
}
385386

386-
public static void enableDartSDK(@NotNull Module module) {
387+
public static void enableDartSDK(final @NotNull Module module) {
387388
if (FlutterSdk.getFlutterSdk(module.getProject()) != null) {
388389
return;
389390
}
@@ -417,10 +418,18 @@ public static void enableDartSDK(@NotNull Module module) {
417418
if (dartSdkPath == null) {
418419
return; // Not cached. TODO call flutterSdk.sync() here?
419420
}
420-
OpenApiUtils.safeRunWriteAction(() -> {
421-
DartPlugin.ensureDartSdkConfigured(module.getProject(), dartSdkPath);
422-
DartPlugin.enableDartSdk(module);
423-
});
421+
422+
// Wrap the write action in a thread-safe way
423+
// See https://github.com/flutter/flutter-intellij/issues/8480
424+
final Application application = ApplicationManager.getApplication();
425+
if (application != null) {
426+
application.invokeLater(() -> {
427+
application.runWriteAction(() -> {
428+
DartPlugin.ensureDartSdkConfigured(module.getProject(), dartSdkPath);
429+
DartPlugin.enableDartSdk(module);
430+
});
431+
});
432+
}
424433
}
425434
}
426435
}

0 commit comments

Comments
 (0)