Skip to content

Commit 4bd5669

Browse files
authored
Open project view for flutter projects (#8573)
This shows the project view for flutter projects on first open: <img width="509" height="312" alt="Screenshot 2025-10-09 at 9 45 30 AM" src="https://github.com/user-attachments/assets/5f4d2fbc-4a55-42cf-9286-e392fb3548c2" /> There's a problem with this fix though, in this scenario: 1. Open the flutter project (this will open to the project view correctly) 2. Close the project 3. Open the project's Android subdirectory (this will open to the android view correctly) 4. Open the top-level flutter project again - this will open to the android view, which isn't what we want So I don't even know if I want to commit this code, because it feels like we are trying to manipulate a mechanism that's already pretty complicated. Any opinions are welcome. (mostly) Fixes [8556](#8556)
1 parent 04f9253 commit 4bd5669

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/io/flutter/FlutterStudioStartupActivity.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@
55
*/
66
package io.flutter;
77

8+
import com.intellij.ide.projectView.ProjectView;
9+
import com.intellij.ide.util.PropertiesComponent;
810
import com.intellij.openapi.application.ReadAction;
11+
import com.intellij.openapi.diagnostic.Logger;
912
import com.intellij.openapi.project.Project;
1013
import com.intellij.util.concurrency.AppExecutorUtil;
1114
import io.flutter.android.AndroidModuleLibraryManager;
1215
import io.flutter.dart.FlutterDartAnalysisServer;
16+
import io.flutter.logging.PluginLogger;
1317
import io.flutter.settings.FlutterSettings;
1418
import io.flutter.utils.AddToAppUtils;
1519
import io.flutter.utils.AndroidUtils;
20+
import io.flutter.utils.FlutterModuleUtils;
1621
import io.flutter.utils.GradleUtils;
22+
import io.flutter.utils.OpenApiUtils;
1723
import org.jetbrains.annotations.NotNull;
1824

1925
public class FlutterStudioStartupActivity extends FlutterProjectActivity {
26+
private static @NotNull Logger LOG = PluginLogger.createLogger(FlutterStudioStartupActivity.class);
27+
private static final String IS_FIRST_OPEN_KEY = "io.flutter.project.isFirstOpen";
28+
private static final String PROJECT_VIEW_ID = "ProjectPane";
29+
2030
private static Void doNonBlockingStartup(@NotNull Project project) {
31+
LOG.info("Project " + project.getName() + ": Executing non-blocking Studio startup");
32+
2133
if (AndroidUtils.isAndroidProject(project)) {
2234
GradleUtils.addGradleListeners(project);
2335
}
@@ -40,5 +52,29 @@ private static Void doNonBlockingStartup(@NotNull Project project) {
4052
public void executeProjectStartup(@NotNull Project project) {
4153
ReadAction.nonBlocking(() -> doNonBlockingStartup(project)).expireWith(FlutterDartAnalysisServer.getInstance(project))
4254
.submit(AppExecutorUtil.getAppExecutorService());
55+
56+
if (!FlutterModuleUtils.declaresFlutter(project)) {
57+
LOG.info("Project " + project.getName() + ": does not declare Flutter; exiting Studio startup before checking project view");
58+
return;
59+
}
60+
61+
// Set project tool window to show the project on first open (Android Studio sometimes opens android view instead).
62+
// See https://github.com/flutter/flutter-intellij/issues/8556.
63+
// Note: After showing the project view, subsequent opens should go to the project view also. However, if the android subdirectory is
64+
// opened, it seems the full project settings will be modified to open to the Android view instead. See
65+
// https://github.com/flutter/flutter-intellij/pull/8573 for more details.
66+
PropertiesComponent properties = PropertiesComponent.getInstance(project);
67+
if (properties == null) return;
68+
if (!properties.isValueSet(IS_FIRST_OPEN_KEY)) {
69+
OpenApiUtils.safeInvokeLater(() -> {
70+
ProjectView projectView = ProjectView.getInstance(project);
71+
if (projectView == null) return;
72+
if (projectView.getPaneIds().contains(PROJECT_VIEW_ID)) {
73+
LOG.info("Project " + project.getName() + ": Setting project tool window to be project view on first open");
74+
projectView.changeView(PROJECT_VIEW_ID);
75+
}
76+
});
77+
properties.setValue(IS_FIRST_OPEN_KEY, "true");
78+
}
4379
}
4480
}

0 commit comments

Comments
 (0)