'Flutter dynamic height fire multiple times with 0 value
I'm trying to make a responsive app with dynamic size using "get.dart" to get the height and width of each device. here is the sample code to get the height and width:
Dimensions class:
import 'package:get/get.dart';
class Dimensions {
static double screenHeight = Get.context!.height;
static double screenWidth = Get.context!.width;
static double pageView = screenHeight/2.64;
}
Whenever I print the value from Main Class using this code :
print("Current height is " + Get.context!.height.toString());
sometimes it will return multiple times with 0 as the first one, here the example:
I/flutter (12775): Current height is 0.0
I/flutter (12775): Current height is 592.0
And because of the first one returns 0, for some reason, all my Containers that use the dynamic size also return 0. is there a way to prevent multiple fires or get the last value to make sure the dynamic size will never be 0?
If I Run from debug it never fires multiple times, but when I try to run using flutter run --release
, 50% times when launching the app will always fire multiple time with 0 as the first value
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|