I'm trying to add fonts to my app but when I declare the fonts in Type.kt
file I get this error saying
Variable 'iranSansFontFamily' must be initialized
Why am I getting this error?
Here's the code:
val CustomTypography = Typography(
bodyLarge = TextStyle(
fontFamily = iranSansFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp
)
)
val iranSansFontFamily = FontFamily(
Font(R.font.iransans_farsi_medium, FontWeight.Medium),
Font(R.font.iransans_farsi_bold, FontWeight.Bold)
)
CodePudding user response:
the declaration of the font family must be on the top of typography, like that:
val iranSansFontFamily = FontFamily(
Font(R.font.iransans_farsi_medium, FontWeight.Medium),
Font(R.font.iransans_farsi_bold, FontWeight.Bold)
)
val CustomTypography = Typography(
bodyLarge = TextStyle(
fontFamily = iranSansFontFamily,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp
)
)