I want to draw gradient line in jetpack compose. I tried some code but it was not correct as my expected.
Expected Output
Actual Output
Code
@Preview(showBackground = true)
@Composable
fun DrawTimeLine() {
Column(Modifier.fillMaxSize()) {
repeat(2) { index ->
val (height, brush) = if (index == 0) {
75.dp to Brush.linearGradient(listOf(Color.Blue, Color.Red))
} else {
25.dp to Brush.linearGradient(listOf(Color.Red, Color.Red))
}
Column(
modifier = Modifier
.fillMaxWidth()
.height(height)
.drawBehind {
drawLine(
brush = brush,
start = Offset(x = center.x, y = 0F),
end = Offset(x = center.x, y = size.height),
strokeWidth = 2.dp.toPx(),
)
}
) {}
}
}
}