flutter dart-define not loading on first build, only on hot restart

501 views Asked by At

main.dart configuration what i got in the first init project.pbxproj

Hi, Im setting flavor for my existing app and encountered an error with String.fromEnvironment. It only get the right flavor when I click "Hot Restart"

Im using Flutter 3.7.10 Here are my flutter doctor -v logs:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.10, on macOS 13.3.1 22E772610a darwin-arm64, locale en-VN)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.79.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

! Doctor found issues in 1 category.
tungakanui@Tnuis-MacBook-Pro avia-flutter % fvm flutter doctor -v
[✓] Flutter (Channel stable, 3.7.10, on macOS 13.3.1 22E772610a darwin-arm64, locale en-VN)
    • Flutter version 3.7.10 on channel stable at /Users/tungakanui/fvm/versions/3.7.10
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4b12645012 (3 months ago), 2023-04-03 17:46:48 -0700
    • Engine revision ec975089ac
    • Dart version 2.19.6
    • DevTools version 2.20.1

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/tungakanui/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.79.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.64.0

[✓] Connected device (3 available)
    • iPhone 14 Pro (mobile) • BF0C1972-F6B0-4164-BDBF-59D6BCF6B117 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.3.1 22E772610a darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 114.0.5735.198

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

I want to get the right Flavor in the first init

2

There are 2 answers

3
user5218414 On

check file : ios/Runner.xcodeproj/project.pdxproject and remove all

buildSettings = {
   DART_DEFINES = "" // <- remove here
}
0
Zaw Htet Naing On

Are you using custom .xcconfig files? If so try adding this line at the bottom of your custom .xcconfig files assuming the files are in Runner folder.

#include "../Flutter/Generated.xcconfig"