尝试使用
导航回来时出现
java.lang.IllegalStateException: Place was called on a node which was placed already
错误
navController.navigateUp()
从某个特定屏幕,我找不到问题所在
我不知道我的导航可能出了什么问题,其他类似的屏幕工作正常
我发现了问题,在第一个屏幕上我有这个代码
LazyVerticalGrid(
modifier = Modifier.padding(start = 0.dp, end = 0.dp),
columns = GridCells.Fixed(2),
) {
item(span = { GridItemSpan(maxLineSpan) }) {
AssetTopItem(
modifier = Modifier
.padding(bottom = 20.dp, start = 15.dp, end = 15.dp),
item = uiState.asset
)
}
item(span = { GridItemSpan(maxLineSpan) }) {
ChartBlock(
chartState = uiState.chartState,
intervalsState = uiState.intervalState,
updateData = updateData,
changeInterval = changeInterval
)
}
item(span = { GridItemSpan(maxLineSpan) }) {
Column(
Modifier
.fillMaxWidth()
.background(
color = backgroundBlack,
shape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp)
)
) {
CryptoTabs(modifier = Modifier, state = uiState.tabsState, setType = setTab)
OrdersBlock(state = uiState.offersState, scope = this@LazyVerticalGrid)
}
}
}
我正在从这个屏幕导航到第二个屏幕,当我导航回来时,我发生了崩溃。但是当我的第一个屏幕上有这样的代码时
LazyVerticalGrid(
modifier = Modifier.padding(start = 0.dp, end = 0.dp),
columns = GridCells.Fixed(2),
) {
item(span = { GridItemSpan(maxLineSpan) }) {
AssetTopItem(
modifier = Modifier
.padding(bottom = 20.dp, start = 15.dp, end = 15.dp),
item = uiState.asset
)
}
item(span = { GridItemSpan(maxLineSpan) }) {
Column(
Modifier
.fillMaxWidth()
.background(
color = backgroundBlack,
shape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp)
)
) {
CryptoTabs(modifier = Modifier, state = uiState.tabsState, setType = setTab)
OrdersBlock(state = uiState.offersState, scope = this@LazyVerticalGrid)
}
}
item(span = { GridItemSpan(maxLineSpan) }) {
ChartBlock(
chartState = uiState.chartState,
intervalsState = uiState.intervalState,
updateData = updateData,
changeInterval = changeInterval
)
}
}
我没有崩溃:)wtf
此异常的原因是对导航库的 alpha 版本的传递依赖
我也面临着与我明确使用项目跨度相同的问题
像下面这样
item(span = { GridItemSpan(maxLineSpan) }) {
...
}
后来我像上面一样删除了它,并使用了
span
参数,它带有 itemsIndexed()
扩展功能
itemsIndexed(
items,
span = { index, item -> (index % 3 == 0).select(GridItemSpan(maxLineSpan), GridItemSpan(1))}
) {}
并且它开始工作,没有崩溃