🖥️

Flutter 2系でiOSでの--dart-defineを受け取る設定方法

2021/07/24に公開

Pre-actionsにRunScriptを追加

Xcode->Product->Scheme->Edit Scheme...->Build->Pre-actions

追加するスクリプト

echo "Pre-actions start"

function entry_decode() { echo "${*}" | base64 --decode; }

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


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

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

echo "Pre-actions end"

※Provide build settings from に「Runner」を選択しておく

サンプル

Discussion