Hey there, do you know if there is a composable li...
# compose
s
Hey there, do you know if there is a composable like this one for Flutter? I’ve managed to kind of replicate the functionality that I required with a combination of a
WithConstraints
composable and a
drawLayer
modifier with scaleX and scaleY, but it was much more cumbersome to achieve my expected result https://api.flutter.dev/flutter/widgets/FittedBox-class.html
1
a
Should be doable with just a modifier, no WithConstraints needed
👀 1
c
@Adam Powell do you have sample code? or any reference material to look into?
a
I would have to look into what flutter's FittedBox does precisely, but from the docs it looks like it applies a scale, potentially a clip, and performs measurement and positioning, probably modifying the constraints for the content
So an implementation of this would probably look like
Copy code
fun Modifier.fittedBox(
  // params
) = composed {
Use a
Modifier.layout {
to do the measurement and positioning chained together with a
.drawLayer
after it to provide the scaling, and an optional clip before the layout if needed by the mode parameter
With a
remember { mutableStateOf(...) }
to share the computed scaling factor between the layout modifier and the drawLayer