Reputation: 39
I used Getx
to Get the height/width and made a Dimensions
class so that dimensions would stay responsive through out the whole app in any device with minimum code
the problem is Get.height
and Get.width
are static and only get values once at run time so if the user switched to landscape or minimized the tab the UI is not updated accordingly
this is the dimensions class
:
import 'package:get/get.dart';
class Dimentions {
static double screenHight = Get.context!.height;
static double screenWidth = Get.context!.width;
//u make a suitable view in pixils then get the page hoght and devide to get the factor
static double pageView = screenHight/2.64;
static double pageViewContainer = screenHight/3.84;
static double pageTextContainer = screenHight/7.03;
//hight
static double hight10 = screenHight/84.4;
static double hight15 = screenHight/56.27;
static double hight20 = screenHight/42.2;
static double hight45 = screenHight/18.76;
static double hight30 = screenHight/28.13;
//width
// ur still using hight maybe u wanna change it later
static double width10 = screenHight/84.4;
static double width15 = screenHight/56.27;
static double width20 = screenHight/42.2;
static double width30 = screenHight/28.13;
static double width45 = screenHight/18.76;
//font size
static double font20= screenHight/42.2;
static double font26 = screenHight/42.2;
static double font16 = screenHight/52.75;
//raduis
static double radius15= screenHight/56.27;
static double radius20= screenHight/42.2;
static double radius30= screenHight/28.13;
//icon size
static double iconSize24 = screenHight/35.17;
static double iconSize16 = screenHight/52.75;
//listview size
static double listViewImageSize = screenWidth/3.25;
static double listViewTextSize = screenWidth/3.9;
//food details
static double foodImagesize= screenHight/2.41;
//bottom hoght
static double bottomHightBar= screenHight/6.25;
//splash screen
static double splashImg= screenHight/3.375;
}
usage example:
SizedBox(
width: Dimentions.width10,
),
i want the screenHight
screenWidth
to get updated dynamically and the use of MediaQuery.of(context).size.height
is not possible since there is no context
here nor it will get automatically updated
Upvotes: 0
Views: 47