Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix: Flutter SDK path in settings is not updated#8827

Open
cj-radcliff wants to merge 5 commits intomainfrom
flutter-sdk-fix-8641
Open

Fix: Flutter SDK path in settings is not updated#8827
cj-radcliff wants to merge 5 commits intomainfrom
flutter-sdk-fix-8641

Conversation

@cj-radcliff
Copy link
Collaborator

The settings page UI for the Flutter SDK path was not updating after being changed. When a user updated the path, applied the change, and re-opened settings, the old path would still be displayed.

This was caused by the settings page reading the SDK path from a stale cache provided by the Dart plugin (FlutterSdk.getFlutterSdk()).

The fix is to use FlutterSdk.getIncomplete() instead, which bypasses the cache and reads the path directly from the authoritative source: the project's Library Table configuration. This ensures the UI always displays the currently configured value.

Fixes: #8641

Thanks for your contribution! Please replace this text with a description of what this PR is changing or adding and why, list any relevant issues, and review the contribution guidelines below.

The settings page UI for the Flutter SDK path was not updating after being changed. When a user updated the path, applied the change, and re-opened settings, the old path would still be displayed.

This was caused by the settings page reading the SDK path from a stale cache provided by the Dart plugin (FlutterSdk.getFlutterSdk()).

The fix is to use FlutterSdk.getIncomplete() instead, which bypasses the cache and reads the path directly from the authoritative source: the project's Library Table configuration. This ensures the UI always displays the currently configured value.

Fixes: #8641
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly identifies and fixes an issue where the Flutter SDK path was not updating in the settings UI by switching from FlutterSdk.getFlutterSdk() to FlutterSdk.getIncomplete(). My review focuses on a necessary improvement to ensure thread safety. The new calls to FlutterSdk.getIncomplete() access the project model from the Event Dispatch Thread (EDT) and must be wrapped in a ReadAction to comply with the IntelliJ Platform's threading rules, as outlined in the repository's style guide. I have provided comments with code suggestions for each occurrence.

cj-radcliff and others added 3 commits February 25, 2026 13:23
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@cj-radcliff cj-radcliff requested review from helin24 and pq February 25, 2026 22:35

private void init() {
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(myProject);
final FlutterSdk sdk = com.intellij.openapi.application.ReadAction.compute(() -> FlutterSdk.getIncomplete(myProject));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to use qualified name instead of importing?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. I don't think there's a good one. Could you fix?

Copy link
Collaborator

@pq pq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works, I'm OK to land it but I have to wonder why the cache is stale and if there aren't other places where getFlutterSdk(...) isn't working as expected -- looks like it's used 40+ times. 🧐

I'm also curious if this is a newly broken bit or if it's been misbehaving for a while and noone has reported it? (More just asking out loud... I don't expect an answer!)

@Override
public void reset() {
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(myProject);
final FlutterSdk sdk = com.intellij.openapi.application.ReadAction.compute(() -> FlutterSdk.getIncomplete(myProject));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix this qualified reference here too.

@pq
Copy link
Collaborator

pq commented Feb 26, 2026

More thoughts: it'd be interesting to ask gemini some follow up questions:

  • Is it likely that this is a regression or a long-standing bug? Is there anything in git history that could explain a breakage? Any changes in platform libraries that could be to blame?
  • If the cache is stale in this case, are there other places where it may also be stale to negative effect?
  • Let's say we don't want to go this route and want to fix the stale cache issue at the root, how would we do that? Might there be any unexpected consequences?

Including the results with the review would be great as a kind of "alternatives considered" addendum.

@pq
Copy link
Collaborator

pq commented Feb 26, 2026

Another question:

  • How would I validate that this change was working as expected? (This might give us a hint for how well gemini "understands" the fix.)

@cj-radcliff: it would be great to include your verification steps too. (That is: how you tested the fix.)

@cj-radcliff
Copy link
Collaborator Author

I asked a few questions of gemini, adding here. @pq I will also ask your questions and follow up further:

Explanation of Cache Fix for Reviewers

Q1: Who introduced the cache and why is it used instead of reading from disk?

A: The commit to fix the issue by bypassing the cache was made by Cory R on Wed Feb 25, 2026. The commit message explains that the original cached method, FlutterSdk.getFlutterSdk(), was provided by the Dart plugin.

The reason a cache is used is for performance. Reading from disk is thousands of times slower than reading from memory. Since many parts of the IDE need the SDK path frequently, caching the value after the first read prevents redundant, slow disk operations and keeps the UI responsive.

The bug occurred because the settings page, which needs the authoritative value from the disk, was incorrectly using the potentially stale cached value. The fix was to use getIncomplete() in that specific location to read the authoritative value.

** NOTE! This answer is partially incorrect because its not what I asked. I include it because the second half seems to be a good answer.

Q2: Does this fix cause normal access methods to read from disk more often?

A: No, it does not. The fix was carefully targeted only to the settings page code (FlutterSettingsConfigurable.java).

Other parts of the plugin that use the cached FlutterSdk.getFlutterSdk() method for normal, frequent operations (like running an app) are completely unaffected. They continue to get the performance benefit of the cache. The direct disk read only happens in the infrequent case of a user opening the settings page, where correctness is more important than a minor performance optimization.

Q3: Is there a way to make the fix by refreshing the cache properly before reading it, instead of bypassing it?

A: While theoretically possible, bypassing the cache is the better and safer design choice in this specific context for several reasons:

  1. Ownership: The cache belongs to the Dart plugin. Forcing a refresh on another component's internal state is risky and can have unintended side effects.
  2. API Availability: There's no guarantee the Dart plugin exposes a public, stable API for forcing a refresh. getIncomplete(), however, is clearly designed for this purpose.
  3. Correctness: A settings page's primary job is to reflect the authoritative source of truth (the configuration on disk). Bypassing a cache to read this ground truth is the most direct and correct design pattern for a UI that edits that truth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter SDK path setting issue

3 participants