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

Integrate with dart-define #35

Open
edTheGuy00 opened this issue Apr 28, 2021 · 3 comments
Open

Integrate with dart-define #35

edTheGuy00 opened this issue Apr 28, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@edTheGuy00
Copy link
Member

--dart-define variables are accesible in gradle with project.property('dart-defines') , and on iOS via ios/Flutter/Generated.xcconfig this could potentially be an alternative to using a .env file, as --dart-define variables are more easily accesible on the flutter engine with String.fromEnvironment("MY_VAR") and int.fromEnvironment("MY_VAR")

Simple script in gradle to make dart-define variables into a map

project.property('dart-defines')
            .split(',')
            .collectEntries { entry ->
                def pair = URLDecoder.decode(entry).split('=')
                [(pair.first()): pair.last()]
            }

Simple Build pre-action script for xcode


function urldecode() { : "${*//+/ }"; echo "${_//%/\\x}"; }

   IFS=',' read -r -a define_items <<< "$DART_DEFINES"

for index in "${!define_items[@]}"
do
    define_items[$index]=$(urldecode "${define_items[$index]}");
done

printf "%s\n" "${define_items[@]}" > ${SRCROOT}/Flutter/Dart-defines.xcconfig

Things to note:

  • This will not be a replacement, but an alternative. Users can either chose to use a .env file or --dart-define
  • If both .env and --dart-define are used, the map for .env variables will be created first and the --dart-define variables will be appended.
@edTheGuy00 edTheGuy00 added the enhancement New feature or request label Apr 28, 2021
@edTheGuy00 edTheGuy00 pinned this issue Apr 28, 2021
@edTheGuy00
Copy link
Member Author

as of Flutter 2.2.0, dart defined variables are base64 encoded.

decode using

gradle:

byte[] decoded = entry.decodeBase64()

iOS:

function base64decode() { echo "$1" | base64 -d ; echo; }

decoded=$(base64decode "${define_items[$index]}");
define_items[$index]=$(urldecode "${decoded[$index]}");

@pepe19000
Copy link

as of Flutter 2.2.0, dart defined variables are base64 encoded.

decode using

gradle:

byte[] decoded = entry.decodeBase64()

iOS:

function base64decode() { echo "$1" | base64 -d ; echo; }

decoded=$(base64decode "${define_items[$index]}");
define_items[$index]=$(urldecode "${decoded[$index]}");

And how can i get key-value pair from decoded variables?

@IlyaOstashkov
Copy link

as of Flutter 2.2.0, dart defined variables are base64 encoded.
decode using
gradle:

byte[] decoded = entry.decodeBase64()

iOS:

function base64decode() { echo "$1" | base64 -d ; echo; }

decoded=$(base64decode "${define_items[$index]}");
define_items[$index]=$(urldecode "${decoded[$index]}");

And how can i get key-value pair from decoded variables?

You can use that https://medium.com/@tatsu.ukraine/flutter-2-2-dart-defines-and-breaking-changes-here-we-go-again-ce40cfea74fd

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

No branches or pull requests

3 participants