yusuf nadaroğlu
yusuf nadaroğlu

Reputation: 43

Flutter Get.width or initialize MediaQuery.of(context).size not working in Release mode

When ı use get.width or height at first page in project or initialize like this ;

 @override
  void didChangeDependencies() {
    SizeConfig().init(context);
    super.didChangeDependencies();
  }

also SizeConfig page :

class SizeConfig {
  static late MediaQueryData _mediaQueryData;
  static late double width;
  static late double height;
  static late double blockSizeHorizontal;
  static late double blockSizeVertical;
  static late double res;

  void init(BuildContext context) {
    _mediaQueryData = MediaQuery.of(context);
    width = _mediaQueryData.size.width;
    height = _mediaQueryData.size.height;
  }

}

It is not working.

But when ı use debug mode they are working well. Yes the release mode faster than debug mode but how can we solve it?

Upvotes: 1

Views: 1537

Answers (1)

ABV
ABV

Reputation: 910

Try below code

void init(BuildContext context) {
    WidgetsBinding.instance!.addPostFrameCallback((_) {
  // executes after build
_mediaQueryData = MediaQuery.of(context);
    width = _mediaQueryData.size.width;
    height = _mediaQueryData.size.height;

});
  }

Upvotes: 2

Related Questions