2

I'm getting height and width of the screen size using Get.context!.height and Get.context!.width. This works perfect in Debug mode. But in the release APK, it's not working at all due to which all the elements based on these are disappearing.

I also tried using MediaQuery but as the height and width are being used inside a class that doesn't have any BuildContext, MediaQuery is not the solution. So I went with Get.context! which works great in debug version. Once I switch to release version, bam, it no longer works.

Here is the code which is not working in release mode but working in debug mode :

class Dimensions {

  static double screenHeight = Get.context!.height;

  static double screenWidth = Get.context!.width;

  static double pageView = screenHeight / 3.08;

  static double pageViewContainer = screenHeight / 4.00;

  static double pageDetailsContainer = screenHeight / 7.40;

  static double imageButtonSectionHeight = screenHeight * 0.195;

}
OMi Shah
  • 5,768
  • 3
  • 25
  • 34

2 Answers2

0

Try using Get.overlayContext instead of Get.context`.

I'm using Getx also, please if this also didn't work, consider passing the context as a parameter from the constructor of that class or from your method and use the MediaQuery.of(context) instead.

the BuildContext topic is essential, and it can also be problematic if used incorrectly.

Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
  • Thank you so much for your time and your comment. I will try with Get.overlayContext and let you know. I tried MediaQuery.of(context) but as this is outside BuildContext, I'm not able to get context into the class. – stevenstarisrael Nov 23 '22 at 11:04
  • Here is my app link : Debug APK : https://www.flikko.com (Works perfectly) Release APK : https://play.google.com/store/apps/details?id=com.theneondesign.flikko – stevenstarisrael Nov 23 '22 at 11:08
  • I tried Get.overlayContext, but it completely broke everything that was working too. Got so many errors. So currently I reverted to Get.context. I'm sharing debug apk to users. Thank you so much and please let me know just in case you find some other solutions. – stevenstarisrael Nov 23 '22 at 12:07
  • Hi again, I tried using your Dimentions class, and the Get.context: throws a null value, after some tries I found out that you need a GetMaterialApp to use the Get.context feature on Getx – Gwhyyy Nov 23 '22 at 12:59
  • so in your App, change MaterialApp with GetMaterialApp and do a hot restart – Gwhyyy Nov 23 '22 at 13:00
  • if it works, please let me know so I can add it as a proper answer for others who might get into this problem – Gwhyyy Nov 23 '22 at 13:01
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/249851/discussion-between-stevenstarisrael-and-gwhyyy). – stevenstarisrael Nov 24 '22 at 04:40
  • sure ! I sent a message – Gwhyyy Nov 24 '22 at 13:42
  • consider accepting this answer since it could helps the next person getting into this trouble ! – Gwhyyy Dec 01 '22 at 20:22
0

This is not working because it takes time to initialize. Only you have to do is take Stateful Widget and use init state method and in init state method, use Timer method and one thing more is do not make return type of init method future otherwise you will face an error. 3 sec is sufficient . You can also you use this widget as your splash screen.

I am suggesting this as i find it after a lot of debugging. I hope it will work for you as well