I’m encountering a strange issue with my Flutter app that has me stumped. Here’s the situation:
- The app works perfectly fine in the emulator (both debug and release modes).
- When I build the APK or test on iOS through TestFlight, some screens are completely grey.
What I’ve Tried:
I searched Stack Overflow and tried several suggestions:
- Removed
Expanded
widgets that might cause layout issues. - Cleared app cache and reinstalled with new build after performing
flutter clean
. - Verified that there are no errors in the logs using
flutter build apk --release -v
. - Commanded out parts of the code, and re-enabled them line by line to isolate the issue.
Finally, I traced the issue to hard-coded data in the controller section of my app. When I removed the variables and directly passed the data (e.g., instead of using a variable to store the data), the grey screen issue disappeared in the APK build.
Important Points:
- No errors in the verbose logs.
- The same code works perfectly fine on the emulator but produces grey screens in the APK build.
- This issue only surfaced after I updated Flutter to the latest version.
Has anyone else experienced a similar issue, especially after a Flutter update? Is there something I should be aware of in the way hard-coded data is handled in production builds, compared to how it’s processed in the emulator?
Any help would be greatly appreciated!
2
Answers
The information you provided is kinda insufficient, so first, I suggest edit your question with detailed information.
Second, this problem seems to be related to flutter’s release build optimizations like Tree-Shaking and Obfuscation. When you’re building a release version, flutter will alter variables that consider them as "unused".
so, I suggest
const
Also make sure that you dont missed any permission in "main" manifest file like:
Try Flutter run –release and check where you’re getting crash.