Stefano Rodriguez

    Stefano Rodriguez

    1 year ago
    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 resulthttps://api.flutter.dev/flutter/widgets/FittedBox-class.html
    Adam Powell

    Adam Powell

    1 year ago
    Should be doable with just a modifier, no WithConstraints needed
    Christian

    Christian

    1 year ago
    @Adam Powell do you have sample code? or any reference material to look into?
    Adam Powell

    Adam Powell

    1 year ago
    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
    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