I think the title says it all.
LazyPagingItems
constructor is internal. I can't pass LazyPagingItems
as parameter in Preview Composable, let alone passing sample data. But I want to show preview of my composable, how should I do this?
@Composable
fun MainUi(users: LazyPagingItems<User>) {
Scaffold {
LazyColumn() {
items(users) {
// Rest of the code..
}
}
}
}
@Preview
@Composable
fun Preview() {
DefaultTheme {
MainUi(users = ) // How to pass sample data here?
}
}
You can use PagingData.empty()
or PagingData.from(List<T>)
, like this:
@Preview
@Composable
fun Preview() {
DefaultTheme {
MainUi(users = flowOf(PagingData.from(listOf(User(..)))).collectAsLazyPagingItems()
}
}
I'm not sure if the items are shown in the preview, but at least you get to render it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With