Flutter –dart-define が空文字になる

Flutter 3.29.3 にて。

String accessToken = String.fromEnvironment("MAPBOX_ACCESS_TOKEN");

ではダメで、const が必要。

String accessToken = const String.fromEnvironment("MAPBOX_ACCESS_TOKEN");

参考: https://stackoverflow.com/a/76718173

追記: 公式ドキュメントにも書いてありました。

https://api.flutter.dev/flutter/dart-core/String/String.fromEnvironment.html

This constructor is only guaranteed to work when invoked as const. It may work as a non-constant invocation on some platforms which have access to compiler options at run-time, but most ahead-of-time compiled platforms will not have this information.

コメント

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です