Jeisson Sáchica
02/01/2021, 10:01 PMjava.lang.NullPointerException: null cannot be cast to non-null type androidx.compose.ui.graphics.AndroidPathEffect
when using a androidx.compose.ui.graphics.PathEffect
on a ContentDrawScope.drawCircle
?Jeisson Sáchica
02/01/2021, 10:03 PMval pathEffectIntervalsDp: Array<Dp> = arrayOf(6.dp, 3.dp)
val strokeWidthDp = 1.dp
@Suppress("UNUSED_VARIABLE")
@Composable
fun DashedCircle(
strokeColor: Color,
modifier: Modifier = Modifier,
) {
val pathEffectIntervals: FloatArray = pathEffectIntervalsDp.map {
with (AmbientDensity.current) { it.toPx() }
}.toFloatArray()
val strokeWidth = with (AmbientDensity.current) { strokeWidthDp.toPx() }
Box(modifier.drawWithCache {
val pathEffect: PathEffect = PathEffect.dashPathEffect(pathEffectIntervals, 1f)
val start = Offset(size.width / 2, size.height / 2)
val end = Offset(size.width, size.height / 2)
onDrawWithContent {
drawCircle(
strokeColor,
style = Stroke(
width = strokeWidth,
// pathEffect = pathEffect
)
)
drawLine(
color = strokeColor,
start = start,
end = end
)
}
})
}
Jeisson Sáchica
02/01/2021, 10:03 PMJeisson Sáchica
02/01/2021, 10:06 PMdrawCircle
, The error occurs on the preview and when running it. Strangely, if I remove the drawLine
and only leave the drawCircle
, it outputs correctly this:Jeisson Sáchica
02/01/2021, 10:18 PMStroke
stopped taking an android.graphics.PathEffect
as DashPathEffect(pathEffectIntervals, 1f)
to now take an a`ndroidx.compose.ui.graphics.PathEffect` as PathEffect.dashPathEffect(pathEffectIntervals, 1f)
Nader Jawad
02/03/2021, 3:14 AMJeisson Sáchica
02/03/2021, 2:13 PMJeisson Sáchica
02/03/2021, 2:15 PM