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

Nat Strangerweather

09/17/2020, 2:14 PM
When making a gradient, I see quite a few examples using this, for instance:
Copy code
endY =150.dp.toPx()
but I get "Unresolved Reference: toPx(). What am I doing wrong?
y

Yann Badoual

09/17/2020, 2:15 PM
You need the density to resolve the px size
🙏 1
☝️ 1
This can be done either in a
DrawScope
, or manually, you can also do
with(DensityAmbient.current) { 150.dp.toPx() }
🙏 1
n

Nat Strangerweather

09/17/2020, 2:15 PM
Ah ok, cheers! 😊
👌 1
this will allow you to create and cache things like gradients across multiple draws, and the Density is available in that scope by default
n

Nat Strangerweather

09/17/2020, 2:18 PM
Oh yeah, this looks ideal!
👍 1
a

Adam Powell

09/17/2020, 2:18 PM
you won't have to worry about calls to remember {}, etc. for it
👌 4
6 Views