neerav
03/22/2024, 5:13 AM@Composable invocations can only happen from the context of a @Composable function
Can anyone please help me or share doc from where i can get idea to fix this ?
Reference taken from : https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-images-resources.html#fonts
ThanksBen Abramovitch
03/22/2024, 5:30 AMval LocalFont = compositionLocalOf<FontFamily?> {null}
@Composable
fun MainView() {
val fontFamily = FontFamily(Font(Res.font.yourfont, weight = FontWeight.Bold))
CompositionLocalProvider(
LocalFont provides fontFamily
) {
Text("hello", fontFamily = LocalFont.currentOrThrow)
}
You could also just make a composable function that returns it
@Composable
fun someFont(): FontFamily {
return FontFamily(Font(Res.font.yourfont, weight = FontWeight.Bold))
}
Text(text = "hello", fontFamily = someFont())
Ben Abramovitch
03/22/2024, 5:39 AMBen Abramovitch
03/22/2024, 5:57 AMMaterialTheme(
typography = Typography(defaultFontFamily = FontFamily(Font(Res.font.yourfont)))
) {
Text(text = "hello", style = MaterialTheme.typography.body1, fontWeight = FontWeight.Bold)
}