Nat Strangerweather

    Nat Strangerweather

    2 years ago
    When making a gradient, I see quite a few examples using this, for instance:
    endY =150.dp.toPx()
    but I get "Unresolved Reference: toPx(). What am I doing wrong?
    Yann Badoual

    Yann Badoual

    2 years ago
    You need the density to resolve the px size
    This can be done either in a
    DrawScope
    , or manually, you can also do
    with(DensityAmbient.current) { 150.dp.toPx() }
    Nat Strangerweather

    Nat Strangerweather

    2 years ago
    Ah ok, cheers! 😊
    this will allow you to create and cache things like gradients across multiple draws, and the Density is available in that scope by default
    Nat Strangerweather

    Nat Strangerweather

    2 years ago
    Oh yeah, this looks ideal!
    Adam Powell

    Adam Powell

    2 years ago
    you won't have to worry about calls to remember {}, etc. for it