When are environment variables available in flutter app? - ios

I'm using Flutter 3.3.10, on macOS 11.6, and I am trying to use env vars at runtime. For the sake of the test I have 2 prints, one in main() and 1 in the build() function, like so:
print(const String.fromEnvironment('APPNAME'));
When I run the app from terminal on an iOS simulator like so: flutter run --dart-define=APPNAME=TEST_APP I get 2 blank prints:
Xcode build done. 10.8s
flutter:
flutter:
It is only after I do a hot restart ('R') that it prints:
Performing hot restart...
Restarted application in 378ms.
flutter: TEST_APP
flutter: TEST_APP
Why are the env vars not available on the first run?
EDIT: Interestingly, I don't get that problem when I run the exact same app on an Android emulator.

Related

Flutter IOS blank screen

I have a flutter app i have developed and it is running efficiently on a real device with zero errors or warnings in debug mode. however when i deploy a release to the same real device it produces a white screen on most pages. I am producing the release using X-code. What could be the problem?
connect your device using cable.
then write following command in terminal.
flutter run
to see error log in terminal in red colors.
Open Terminal and Go to /ios folder inside your project.
Executes pod deintegrate command.
Then after pod install
Run your project Flutter run

How to add dart run time command arguments to Xcode

When I am running a flutter app I need to add this argument. Otherwise, the app is not working.
--no-sound-null-safety
Example:
flutter build apk --no-sound-null-safety
or
flutter run --no-sound-null-safety
It's easy to add on android studio. (Edit configurations..). But, I didn't know how to add this kind of argument on Xcode?
add EXTRA_FRONT_END_OPTIONS in User-Defined in Build Settings. value is --no-sound-null-safety
just keep running code in vs or android studio then open in xcode it will not throw null safety issue for any deprecated package

How to run Flutter app on multiple iOS simulators at the same time?

I tried running flutter run -d all, but I always get these errors:
s
NULL
** BUILD FAILED **
Xcode's output:
↳
note: Using new build system
note: Building targets in parallel
error: Build service could not start build operation: unknown error while handling message: Could not acquire
This command works if I try running both Android emulator and iOS simulator, but never for two or more iOS simulators at the same time.
There's a known issue in the Flutter SDK where it uses Xcode's latest build system, which prohibits the concurrent builds to run with a single flutter run command.
If you want to test your app against multiple devices at the same time, run the following:
flutter devices
flutter run -d <device_id_iphone> && flutter run -d <device_id_ipad>
The catch for this workaround is you have two isolated Flutter app instances running.
If you're running them on the command line, you have to reload each instance individually.

Flutter error when build on real device (build flutter demo application)

I just create an app from flutter with demo application, I didn't add anything, just run
1
flutter create app_test_001
2
flutter create .
3
flutter build ios --release
When I run the emulator, it shows the default simple application
and when I run it on my iphone it gets the white screen
Result on emulador
Result in real device
Try this:
Make sure everything is right flutter doctor
Restart your computer
Check if your mobile device is updated
Also, these issues can relate: https://github.com/flutter/flutter/issues/18409

How does Flutter driver work with Android?

In android world to run UI test with ADB, you need to execute this command
adb shell am instrument -w com.tarek360.sample.test
but before running this command you need to install your test package and main application Android package files (.apk files) to your current Android device or emulator, more info here.
Normally the APKs package names will be in the following format:
Main APK: com.tarek360.sample
Test APK: com.tarek360.sample.test
but in Flutter world, when I run flutter drive, for example, the following command:
flutter drive --target=test_driver/app.dart
I see only the main APK has installed and I don't see any test APK has installed on my device, I'm wondering how does Flutter Driver works with Android, it's important for me to understand because I have very customized CI and I build APKs in a completely different environment than the test runner environment.
Tests on your computer use Flutter Driver to connect to Flutter Driver Extension, that you must enable separately, inside your application using TCP and send commands to it using adb with port forwarding

Resources