|
9 | 9 | import com.intellij.execution.RunnerAndConfigurationSettings; |
10 | 10 | import com.intellij.facet.Facet; |
11 | 11 | import com.intellij.facet.FacetManager; |
| 12 | +import com.intellij.openapi.application.Application; |
12 | 13 | import com.intellij.openapi.application.ApplicationManager; |
13 | 14 | import com.intellij.openapi.fileEditor.FileEditor; |
14 | 15 | import com.intellij.openapi.fileEditor.FileEditorManager; |
@@ -383,7 +384,7 @@ public static void setFlutterModuleAndReload(@NotNull Module module, @NotNull Pr |
383 | 384 | ProjectManager.getInstance().reloadProject(project); |
384 | 385 | } |
385 | 386 |
|
386 | | - public static void enableDartSDK(@NotNull Module module) { |
| 387 | + public static void enableDartSDK(final @NotNull Module module) { |
387 | 388 | if (FlutterSdk.getFlutterSdk(module.getProject()) != null) { |
388 | 389 | return; |
389 | 390 | } |
@@ -417,10 +418,18 @@ public static void enableDartSDK(@NotNull Module module) { |
417 | 418 | if (dartSdkPath == null) { |
418 | 419 | return; // Not cached. TODO call flutterSdk.sync() here? |
419 | 420 | } |
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 | + } |
424 | 433 | } |
425 | 434 | } |
426 | 435 | } |
0 commit comments