Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter support for --dart-define in vscode plugin. #2641

Closed
nvsravank opened this issue Jul 15, 2020 · 6 comments
Closed

Flutter support for --dart-define in vscode plugin. #2641

nvsravank opened this issue Jul 15, 2020 · 6 comments
Labels
in docs / website Relates to documentation, including the Dart Code website
Milestone

Comments

@nvsravank
Copy link

Currently the plugin allows additional arguments to be sent to all flutter commands.
While this maybe useful in some cases the utility is diminished when I am trying to use the Dart feature to send defines that can then be utilized to setup the environment correctly.

The reason for dart define is to utilize compile time variables as discussed in this article.
https://itnext.io/flutter-1-17-no-more-flavors-no-more-ios-schemas-command-argument-that-solves-everything-8b145ed4285d

Now when I add the ---define argument in vccode section for preferences/ settings, the only place to add it is in the
"Dart: Flutter Additional Args" section.
This breaks all other commands that are super useful like the automatic flutter get.

The request is to separate the --dart-define into its own setting that is they used only for the flutter run command and not for all the other flutter commands

@DanTup
Copy link
Member

DanTup commented Jul 15, 2020

Arguments for flutter run can be defined in the launch.json file. If you don't already have one, you can create one using the Debug: Open launch.json command in VS Code, then selecting Dart & Flutter. You can then add an args field, like this:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Dart",
			"program": "lib/main.dart",
			"request": "launch",
			"type": "dart",
			"args":[
				"--dart-define=xyz"
			]
		}
	]
}

Having this as a setting makes less sense, as they tend to be quite application-specific. This way you can easily switch between launch configurations (on the Run side bar).

Let me know if you have any issues with this!

@DanTup DanTup added the awaiting info Requires more information from the customer to progress label Jul 15, 2020
@nvsravank
Copy link
Author

nvsravank commented Jul 15, 2020 via email

@DanTup
Copy link
Member

DanTup commented Jul 16, 2020

These don't show up in the code completion, as these args are not known to VS Code - you can just pass any arguments that Flutter supports (and VS Code does not have a list of these - they may also change across Flutter versions).

I did experiment with just hard-coding some in completion (see #2497 (comment)), however I'm concerned about maintaining them, and also it makes it look like you cannot enter your own.

I think we should probably have a page in the docs that can easily be found if you search the web for "using --dart-define in VS Code" or similar though, so I'll keep this open for that.

@DanTup DanTup added in docs / website Relates to documentation, including the Dart Code website and removed awaiting info Requires more information from the customer to progress labels Jul 16, 2020
@DanTup DanTup added this to the v3.13.0 milestone Jul 16, 2020
@Musharaf13
Copy link

Thank you so much it worked.

@uc-dve
Copy link

uc-dve commented Jul 27, 2021

Arguments for flutter run can be defined in the launch.json file. If you don't already have one, you can create one using the Debug: Open launch.json command in VS Code, then selecting Dart & Flutter. You can then add an args field, like this:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Dart",
			"program": "lib/main.dart",
			"request": "launch",
			"type": "dart",
			"args":[
				"--dart-define=xyz"
			]
		}
	]
}

Having this as a setting makes less sense, as they tend to be quite application-specific. This way you can easily switch between launch configurations (on the Run side bar).

Let me know if you have any issues with this!

I have tried the above but it did not worked below is the syntax which worked for me

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Flutter",
            "request": "launch",
            "type": "dart",
            "args": [
                "--dart-define", "UC_APP_NAME=Comptia_test",
                "--dart-define", "UC_APP_SUFFIX=.comptia.test",
                "--dart-define", UC_APP_ICON=uc_comptia_test",
            ],
            "console": "debugConsole",
        }
    ]
}

@Hwan-seok
Copy link

official docs:
https://dartcode.org/docs/using-dart-define-in-flutter/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in docs / website Relates to documentation, including the Dart Code website
Projects
None yet
Development

No branches or pull requests

5 participants