我正在传递数据以将列表呈现为Flow<>
. 如果它是空的,而不是列表,我需要显示题词“无数据”。如何设置条件来检查流是否为空?
@Composable
fun HistoryLayout(viewModel: HistoryViewModel = viewModel()) {
val historyFlow = viewModel.historyStateFlow.collectAsLifecycleState().value
if (is historyFlow empty???) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Text(
stringResource(R.string.emptylist),
textAlign = TextAlign.Center,
maxLines = MAX_LINES,
overflow = TextOverflow.Ellipsis,
)
}
} else {
HistoryTableList(historyFlow = historyFlow)
}
}