From 8e6d697fa0554e27c123a6621962a92d5a96a82f Mon Sep 17 00:00:00 2001 From: Jaime Wren Date: Tue, 26 Aug 2025 20:04:55 -0700 Subject: [PATCH] Write action fix in FlutterModuleUtils This resolves https://github.com/flutter/flutter-intellij/issues/8480 --- src/io/flutter/utils/FlutterModuleUtils.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/io/flutter/utils/FlutterModuleUtils.java b/src/io/flutter/utils/FlutterModuleUtils.java index 1705860fc..72d500db0 100644 --- a/src/io/flutter/utils/FlutterModuleUtils.java +++ b/src/io/flutter/utils/FlutterModuleUtils.java @@ -9,6 +9,7 @@ import com.intellij.execution.RunnerAndConfigurationSettings; import com.intellij.facet.Facet; import com.intellij.facet.FacetManager; +import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -384,7 +385,7 @@ public static void setFlutterModuleAndReload(@NotNull Module module, @NotNull Pr ProjectManager.getInstance().reloadProject(project); } - public static void enableDartSDK(@NotNull Module module) { + public static void enableDartSDK(final @NotNull Module module) { if (FlutterSdk.getFlutterSdk(module.getProject()) != null) { return; } @@ -418,10 +419,18 @@ public static void enableDartSDK(@NotNull Module module) { if (dartSdkPath == null) { return; // Not cached. TODO call flutterSdk.sync() here? } - OpenApiUtils.safeRunWriteAction(() -> { - DartPlugin.ensureDartSdkConfigured(module.getProject(), dartSdkPath); - DartPlugin.enableDartSdk(module); - }); + + // Wrap the write action in a thread-safe way + // See https://github.com/flutter/flutter-intellij/issues/8480 + final Application application = ApplicationManager.getApplication(); + if (application != null) { + application.invokeLater(() -> { + application.runWriteAction(() -> { + DartPlugin.ensureDartSdkConfigured(module.getProject(), dartSdkPath); + DartPlugin.enableDartSdk(module); + }); + }); + } } } }