Skip to content

Commit 7db044d

Browse files
authored
Fix FlutterAppAction presentation access (#8067)
Fixes: #8061 Also addresses some unsafe unboxing. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
1 parent 18407d2 commit 7db044d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

flutter-idea/src/io/flutter/actions/FlutterAppAction.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ abstract public class FlutterAppAction extends DumbAwareAction {
2323
@NotNull private final Computable<Boolean> myIsApplicable;
2424
@NotNull private final String myActionId;
2525

26+
// The current action event.
27+
private AnActionEvent myEvent;
2628
private final FlutterApp.FlutterAppListener myListener = new FlutterApp.FlutterAppListener() {
2729
@Override
2830
public void stateChanged(FlutterApp.State newState) {
29-
getTemplatePresentation().setEnabled(myApp.isStarted() && myIsApplicable.compute());
31+
// Access the action presentation through the most recently cached action event.
32+
if (myEvent != null) {
33+
myEvent.getPresentation().setEnabled(myApp.isStarted() && Boolean.TRUE.equals(myIsApplicable.compute()));
34+
}
3035
}
3136
};
3237
private boolean myIsListening = false;
@@ -71,10 +76,13 @@ private void updateActionRegistration(boolean isConnected) {
7176
public void update(@NotNull final AnActionEvent e) {
7277
updateActionRegistration(myApp.isConnected());
7378

74-
final boolean isConnected = myIsApplicable.compute();
79+
final boolean isConnected = Boolean.TRUE.equals(myIsApplicable.compute());
7580
final boolean supportsReload = myApp.getMode().supportsReload();
7681
e.getPresentation().setEnabled(myApp.isStarted() && isConnected && supportsReload);
7782

83+
// Cache the current event so that listeners can access its presentation.
84+
myEvent = e;
85+
7886
if (isConnected) {
7987
if (!myIsListening) {
8088
getApp().addStateListener(myListener);

0 commit comments

Comments
 (0)