Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get new widget's width and height after being scaled using Transformer.scale

i have the following code for scaling widget

double  scale= 0.8;
double widthAndHeight = 200 ;
@override
  Widget build(BuildContext context) {
    return  Scaffold(
      body: Center(
        child: GestureDetector(
            onScaleUpdate: (detail){
              scale=detail.scale;
              setState(() {});
            },
          child: Transform.scale(
            scale: scale,
            child: Container(
              color: Colors.blueAccent,
              width: widthAndHeight,
              height: widthAndHeight,
            ),
          ),
        ),
      )
    );
  }
}

The scaling is done correctly but I noticed that the width and height of the original container which is 200 remain exactly the same even though the scaling has been changed and updated !!

Question : How can I get the new real width and height of the container after each scalin
and updating proces

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Note : I tried to used LayoutBuilder() to try to find the new width and height, but it also gives the same first value !

>Solution :

in this case, Transform will not update your widthAndHeight, it just calculate new width and height with your scale value.

So the easiest way to get new width and height is write your own function :

double getNewWidthAndHeight => scale * widthAndHeight
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading