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
Note : I tried to used LayoutBuilder() to try to find the new width and height, but it also gives the same first value !
CodePudding user response:
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
