I am having this problem where it says the non nuablle variable must be initialized
static MediaQueryData _mediaQueryData;
static double screenWidth;
static double screenHeight;
static double deafualtSize;
static Orientation orientation;
void init(BuildContext context) {
_mediaQueryData = MediaQuery.of(context);
screenWidth = _mediaQueryData.size.width;
screenHeight = _mediaQueryData.size.height;
orientation = _mediaQueryData.orientation;
}
}
Ig you need to do something like this
static MediaQueryData _mediaQueryData = 0;
static double screenWidth = 0;
static double screenHeight = 0;
static double deafualtSize = 0;
static Orientation? orientation;
void init(BuildContext context) {
_mediaQueryData = MediaQuery.of(context);
screenWidth = _mediaQueryData.size.width;
screenHeight = _mediaQueryData.size.height;
orientation = _mediaQueryData.orientation;
}
}
Everythime you use the orientation variable you will have to call it like orientation!
This error is because of the new null safety feature. You have to either give a default value or say that the variable can be null by using a ? after the type declaration as in the example above
Hope it helps. Let me know if there is any other problem
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments