diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bb36a055c..35918bfc2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## Unreleased + +### Added + +### Removed + +### Changed + +- Resolved a "Slow operations are prohibited on EDT" exception on Flutter Project creation (#8446, #8447, #8448) + ## 87.1 - Register VM service with DTD (#8436) diff --git a/src/io/flutter/utils/FlutterModuleUtils.java b/src/io/flutter/utils/FlutterModuleUtils.java index cd51276d49..1705860fcd 100644 --- a/src/io/flutter/utils/FlutterModuleUtils.java +++ b/src/io/flutter/utils/FlutterModuleUtils.java @@ -277,28 +277,31 @@ public static void autoCreateRunConfig(@NotNull Project project, @NotNull PubRoo public static void autoShowMain(@NotNull Project project, @NotNull PubRoot root) { if (project.isDisposed()) return; - final VirtualFile main = root.getFileToOpen(); - if (main == null) return; + // Offload the slow file system lookup to a background thread. + ApplicationManager.getApplication().executeOnPooledThread(() -> { + final VirtualFile main = root.getFileToOpen(); - DumbService.getInstance(project).runWhenSmart(() -> { - final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); - if (fileEditorManager == null) { - return; - } - FileEditor[] editors = fileEditorManager.getAllEditors(); - if (editors.length > 1) { - return; - } - for (FileEditor editor : editors) { - if (editor == null) { - return; - } - VirtualFile file = editor.getFile(); - if (file != null && file.equals(main) && FlutterUtils.isDartFile(file)) { - return; - } + // If the file is found, switch back to the EDT to safely update the UI. + if (main != null && main.exists() && !main.isDirectory()) { + DumbService.getInstance(project).runWhenSmart(() -> { + if (project.isDisposed()) return; + + final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); + if (fileEditorManager == null) return; + + FileEditor[] editors = fileEditorManager.getAllEditors(); + if (editors.length > 1) return; + + for (FileEditor editor : editors) { + if (editor == null) return; + + VirtualFile file = editor.getFile(); + if (file != null && file.equals(main) && FlutterUtils.isDartFile(file)) return; + } + + fileEditorManager.openFile(main, editors.length == 0); + }); } - fileEditorManager.openFile(main, editors.length == 0); }); }