18
18
import io .flutter .sdk .FlutterSdkVersion ;
19
19
import io .flutter .utils .AsyncUtils ;
20
20
import io .flutter .utils .OpenApiUtils ;
21
+ import io .flutter .view .ViewUtils ;
21
22
import kotlin .coroutines .Continuation ;
22
23
import org .jetbrains .annotations .NotNull ;
23
24
27
28
public class DeepLinksViewFactory implements ToolWindowFactory {
28
29
@ NotNull private static String TOOL_WINDOW_ID = "Flutter Deep Links" ;
29
30
31
+ @ NotNull
32
+ private final ViewUtils viewUtils = new ViewUtils ();
33
+
30
34
@ Override
31
35
public Object isApplicableAsync (@ NotNull Project project , @ NotNull Continuation <? super Boolean > $completion ) {
32
- FlutterSdk sdk = FlutterSdk .getFlutterSdk (project );
33
- FlutterSdkVersion sdkVersion = sdk == null ? null : sdk .getVersion ();
34
- return sdkVersion != null && sdkVersion .canUseDeepLinksTool ();
36
+ // Due to https://github.com/flutter/flutter/issues/142521, this always returns true when the
37
+ // Flutter IJ plugin is installed.
38
+
39
+ // The logic which asserts that the Flutter SDK is up to date enough for this particular feature
40
+ // is captured in the implementation of createToolWindowContent() below.
41
+
42
+ return true ;
35
43
}
36
44
37
45
@ Override
38
46
public void createToolWindowContent (@ NotNull Project project , @ NotNull ToolWindow toolWindow ) {
39
- FlutterSdk sdk = FlutterSdk .getFlutterSdk (project );
40
- FlutterSdkVersion sdkVersion = sdk == null ? null : sdk .getVersion ();
47
+ final FlutterSdk flutterSdk = FlutterSdk .getFlutterSdk (project );
48
+ final FlutterSdkVersion flutterSdkVersion = flutterSdk == null ? null : flutterSdk .getVersion ();
49
+
50
+ // There are four potential states for the Flutter SDK:
51
+ // 1. The Flutter SDK is null (flutterSdk == null) (an SDK path is invalid or not configured)
52
+ // 2. The Flutter SDK exists, but version file information is unavailable (flutterSdkVersion == null),
53
+ // see https://github.com/flutter/flutter/issues/142521.
54
+ // 3. The Flutter SDK exists, and the version file information is available, but this tool is not
55
+ // available on the version of the SDK that the user has.
56
+ // 4. The Flutter SDK exists with valid version information.
57
+
58
+ // First case:
59
+ if (flutterSdk == null ) {
60
+ viewUtils .presentLabels (toolWindow , List .of ("Set the Flutter SDK path in" ,
61
+ "Settings > Languages & Frameworks > Flutter," ,
62
+ "and then restart the IDE." ));
63
+ return ;
64
+ }
65
+
66
+ // Second case:
67
+ if (flutterSdk .getVersion ().fullVersion ().equals (FlutterSdkVersion .UNKNOWN_VERSION )) {
68
+ viewUtils .presentLabels (toolWindow , List .of ("A Flutter SDK was found at the location" ,
69
+ "specified in the settings, however the directory" ,
70
+ "is in an incomplete state. To fix, shut down the IDE," ,
71
+ "run `flutter doctor` or `flutter --version` in the" ,
72
+ "Flutter SDK directory, and then restart the IDE." ));
73
+ return ;
74
+ }
75
+
76
+ // Third case:
77
+ if (!flutterSdkVersion .canUseDeepLinksTool ()) {
78
+ final String versionText = flutterSdkVersion .fullVersion ();
79
+ viewUtils .presentLabels (toolWindow , List .of ("The version of your Flutter SDK," ,
80
+ versionText + "," ,
81
+ "is not recent enough to use this tool." ,
82
+ "Update the Flutter SDK, `flutter upgrade`," ,
83
+ "and then restart the IDE." ));
84
+ return ;
85
+ }
41
86
87
+ // Final case:
42
88
AsyncUtils .whenCompleteUiThread (
43
89
DevToolsService .getInstance (project ).getDevToolsInstance (),
44
90
(instance , error ) -> {
@@ -60,7 +106,7 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
60
106
.setDevToolsPort (instance .port ())
61
107
.setPage ("deep-links" )
62
108
.setEmbed (true )
63
- .setFlutterSdkVersion (sdkVersion )
109
+ .setFlutterSdkVersion (flutterSdkVersion )
64
110
.setWorkspaceCache (WorkspaceCache .getInstance (project ))
65
111
.setIdeFeature (DevToolsIdeFeature .TOOL_WINDOW )
66
112
.build ();
0 commit comments