导入冲突,导入名称不明确'NavArgs' - 喷气背包撰写导航 拉姆科斯塔



我有两个屏幕可组合与目的地注释(PlaceListingScreen和PlaceInfoScreen与参数),当我添加新的目的地AddEditPlaceScreen与参数。这导致错误消息导入冲突,导入的名称'NavArgs'是不明确的。我已经尝试了没有addedditplacescreen的论据,然后正常工作。在以前,我使用版本1.1.2 beta。应用程序运行正常与AddEditPlaceScreen参数,但当我更新版本到1.5.11-beta它导致错误。

NavArgsGetter错误。kt(在生成的构建文件夹下)

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.lifecycle.SavedStateHandle
import com.example.medisyclinics.presentation.destinations.AddEditPlaceScreenDestination
import com.example.medisyclinics.presentation.destinations.AddEditPlaceScreenDestination.NavArgs
import com.example.medisyclinics.presentation.destinations.PlaceInfoScreenDestination
import com.example.medisyclinics.presentation.destinations.PlaceInfoScreenDestination.NavArgs
@ExperimentalMaterial3Api
inline fun <reified T> SavedStateHandle.navArgs(): T {
return navArgs(T::class.java, this)
}
@Suppress("UNCHECKED_CAST")
@ExperimentalMaterial3Api
fun <T> navArgs(argsClass: Class<T>, savedStateHandle: SavedStateHandle): T {
return when (argsClass) {
AddEditPlaceScreenDestination.NavArgs::class.java -> AddEditPlaceScreenDestination.argsFrom(savedStateHandle) as T
PlaceInfoScreenDestination.NavArgs::class.java -> PlaceInfoScreenDestination.argsFrom(savedStateHandle) as T
else -> error("Class ${argsClass} is not a navigation arguments class!")
}
}

PlaceInfoScreen.kt

@Destination
@Composable
fun PlaceInfoScreen(
placeId: Int,
navigator: DestinationsNavigator,
viewModel: PlaceInfoViewModel = hiltViewModel(),
) {
..... the rest of codes

AddEditPlaceScreen.kt

@Destination
@Composable
fun AddEditPlaceScreen(
isEditMode: Boolean = false,
place: PlaceListing? = null
viewModel: AddEditPlaceViewModel = hiltViewModel()
) {
... the rest of codes

我用数据类作为NavArgs并在目的地注释中使用参数navArgsDelegate为AddEditPlaceScreen解决了这个问题。在我阅读了更新的文档和示例代码应用程序后,我错过了一些新的东西。对不起…

data class AddEditPlaceNavArgs(
val isEditMode: Boolean = false,
val place: PlaceListing? = null
)
@Destination(navArgsDelegate = AddEditPlaceNavArgs::class)
@Composable
fun AddEditPlaceScreen(
val navArgs: AddEditPlaceNavArgs,
viewModel: AddEditPlaceViewModel = hiltViewModel()
) {
... the rest of codes

最新更新