Skip to content

env variables are not passed to dart vm #165

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

Closed
GioPan04 opened this issue Mar 29, 2021 · 4 comments
Closed

env variables are not passed to dart vm #165

GioPan04 opened this issue Mar 29, 2021 · 4 comments

Comments

@GioPan04
Copy link

The env variables defined in the host system are not passed to the dartvm.

Example:

void main() {
  final String user = Platform.environment['USER'];
  print(user);
}

This will output null.

Since you can't build a bundle with --dart-define, there is any way to pass a env variable to the flutter app?

@pezi
Copy link

pezi commented Mar 30, 2021

I can not confirm this behavior - tested inside my flutter app

    print(Platform.resolvedExecutable);
    print(Platform.environment['PATH']);

works fine

flutter: /usr/local/bin/flutter-pi
flutter: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/opt/dart-sdk/bin

@ardera
Copy link
Owner

ardera commented Mar 30, 2021

From a first look it seems like Platform.environment internally delegates to the dart runtime, which will in turn just copy everything from from environ. Don't know why it shouldn't work, the implementation is exactly the same for linux desktop and for android too, but I'll test it

EDIT: Seems like it works fine for me using debug & release mode with and without sudo. Can you try iterating through Platform.environment and printing out the contents to see if maybe some other variables are defined for you?

@GioPan04
Copy link
Author

Okay, I'll test this

@zoechi
Copy link

zoechi commented Jun 8, 2022

Platform.environment['varname'] and String.fromEnvironment('varname') both worked for me in debug mode.
In release mode only Platform.environment['varname'] worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants