When making a gradient, I see quite a few examples using this, for instance: ```endY =150.dp.toPx()`...
n
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
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
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
Oh yeah, this looks ideal!
👍 1
a
you won't have to worry about calls to remember {}, etc. for it
👌 4