0

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

3
  • "[...] and the use of MediaQuery.of(context).size.height is not possible since there is no context here" - so where do you want to use, for example, Dimentions.width10 where there is no BuildContext?
    – pskink
    Commented Jan 9 at 11:48
  • there is no context in this dimension class passing context with each use is a way to go about it but it's a lot of work i use getx so i dont have to deal with context! Commented Jan 9 at 16:52
  • you dont have to pass context on every call just make Dimentions(this.context) constructor and instead of static double xxxx = .... make double get xxxx = ... getters - at the end instead of Dimentions.width10 you would use dimentions.width10
    – pskink
    Commented Jan 9 at 17:00

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.