https://kotlinlang.org logo
#compose
Title
# compose
s

Stefano Rodriguez

11/03/2020, 9:18 AM
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

Adam Powell

11/03/2020, 2:34 PM
Should be doable with just a modifier, no WithConstraints needed
👀 1
c

Christian

11/03/2020, 2:39 PM
@Adam Powell do you have sample code? or any reference material to look into?
a

Adam Powell

11/03/2020, 2:42 PM
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
2 Views