flutter-intellij
flutter-intellij copied to clipboard
"Additional run args" do not resolve and execute shell commands with --dart-define option
Steps to Reproduce
There are no specific requirements. Just having Flutter SDK configured and Intellij IDEA with Flutter Intellij plugin installed.
# 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:
$ 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
:
As it can be seen on following output, --input
is interpreted as the next argument of flutter
command.
Moreover, when single command (without any arguments) is used, like pwd
, it is interpreted as string $(pwd)
, not a command.
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.
<cut>@<cut> ~ % 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/<cut>/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/<cut>/Development/SDK/android
• Platform android-31, build-tools 31.0.0
• ANDROID_HOME = /Users/<cut>/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.
Landed here today after a flutter upgrade (I'm on 3.16.3) when I realized my --dart-define
$(ipconfig getifaddr en0)
function is no longer evaluating and causing the literal string $(ipconfig getifaddr en0) to be set as the environment variable. Issue not specific to intellij as I'm using vscode.