Shahzad Ansari
02/22/2024, 6:39 PMcompanion object
in my data models and define an extension property to get a sample for that data model lazily.
data class User(val name: String, val age: Int) {
companion object
}
val User.Companion.mock by lazy { User(name = "John", age = 25) }
And I use this mock property to get sample data for my @Preview
in Jetpack Compose. Since code defined in @Preview
composable does not become part of live app or APK, I am wondering if it's okay to use this approach.
@Preview
@Composable
fun UserInfo() {
Text(User.mock.toString())
}
Stylianos Gakis
02/22/2024, 9:39 PMmock
appear in autocomplete sometimes, but the alternatives aren't all that good either tbhShahzad Ansari
02/24/2024, 12:17 PMStylianos Gakis
02/24/2024, 12:18 PMShahzad Ansari
02/24/2024, 12:21 PMStylianos Gakis
02/24/2024, 1:09 PMShahzad Ansari
02/24/2024, 4:22 PMfun
sounds safer. Thanks 👍