flutter / flutter/flutter-intellij

"Additional run args" do not resolve and execute shell commands with --dart-define option

Open
#7,070 1 comment 6 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
356
Avg merge
1d 11h
Merged PRs (30d)
27

Description

## Steps to Reproduce

There are no specific requirements. Just having Flutter SDK configured and Intellij IDEA with Flutter Intellij plugin installed.

```shell
# Create default demo app
$ flutter create demo && cd demo

# Create dummy config file
$ echo '{"key": "value"}' > config.json
```

There is no issue when passing `--dart-define` argument with dynamically loaded value through command in shell:

```shell
$ flutter run --dart-define APP_CONFIG=$(base64 --input config.json)
# or
$ flutter run --dart-define=APP_CONFIG=$(base64 --input config.json)
```

When reading from env variable in code, the expected output of base64 encoded content of `config.json` file is single string `eyJrZXkiOiAidmFsdWUifQo=`.

Environment variable can be printed in `Text` widget using `String.fromEnvironment('APP_CONFIG')` for debugging purposes.

The issue is related to `Additional run args` field that splits all arguments by `whitespace`. Hence, the `APP_CONFIG` value is `$(base64` and `flutter` command interprets `--input` as the next argument, rather than converting command `$(base64 --input config.json)` to base64 encoded string first.

Even if `--dart-define` pasted as single line, it is automatically wrapped by `whitespace`:

![image](https://github.com/flutter/flutter-intellij/assets/14924566/0e8cbdf3-0f63-4ae0-a758-ec13b4716ace)

As it can be seen on following output, `--input` is interpreted as the next argument of `flutter` command.

![image](https://github.com/flutter/flutter-intellij/assets/14924566/1b323560-52e6-4808-9c10-d9e8a2b840b8)

Moreover, when single command (without any arguments) is used, like `pwd`, it is interpreted as string `$(pwd)`, not a command.

![image](https://github.com/flutter/flutter-intellij/assets/14924566/409bfeb4-8b6e-4a3d-8036-a3fce2a4f2fb)

Workaround for this issue was not found. It is preferred to load some "sensitive" values or longer strings dynamically from different sources, rather than hardcoding them into `Run/Debug Configurations`.

Related issue: https://github.com/flutter/flutter-intellij/issues/4588

## Version info

Skip following warnings/issues as they are not related to described problem.

```log
@ ~ % flutter doctor -v
Could not parse java version from:

If there is a version please look for an existing bug https://github.com/flutter/flutter/issues/ and if one does not exist file a new issue.
[✓] Flutter (Channel stable, 3.13.8, on macOS 14.1 23B74 darwin-arm64, locale en-PL)
• Flutter version 3.13.8 on channel stable at /Users//Development/SDK/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 6c4930c4ac (3 weeks ago), 2023-10-18 10:57:55 -0500
• Engine revision 767d8c75e8
• Dart version 3.1.4
• DevTools version 2.25.0

[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users//Development/SDK/android
• Platform android-31, build-tools 31.0.0
• ANDROID_HOME = /Users//Development/SDK/android
• Java binary at: /usr/bin/java
✗ Could not determine java version
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15A507
• CocoaPods version 1.11.2

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] IntelliJ IDEA Community Edition (version 2023.2.5)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 76.3.4
• Dart plugin version 232.10072.19

[✓] VS Code (version 1.84.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.76.0

[✓] Connected device (3 available)
• iPhone 15 (mobile) • 701FDC1C-68CB-49CE-B46D-C3CF71A1D70E • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
• macOS (desktop) • macos • darwin-arm64 • macOS 14.1 23B74 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.123

[✓] Network resources
• All expected network resources are available.

! Doctor found issues in 2 categories.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.