When making a gradient, I see quite a few examples...
# compose
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