撰写深层链接导致我的视​​图模型数据为空

发布于 2025-02-09 04:08:54 字数 1108 浏览 0 评论 0原文

我正在研究一个使用JetPack组成的项目,每当我通过深层链接加载合并时,任何快速加载的数据就会出现,然后丢失。

我的深层链接非常直截了当。

composable(
                DestinationScreen.Screen.route + "/{index}",
                arguments = listOf(navArgument("index") { type = NavType.StringType }),
                deepLinks = listOf(navDeepLink { uriPattern ="pattern/job/{index}" })

            ) { entry ->
                LaunchedEffect(Unit) {
                    bottomBarState.value = false
                }
                JobDetails(navController = navController, companyVm = companyViewModel,vm, jobVm,entry.arguments?.getString("index")!!  )
            }

在我的组合中,我有一个启动效果,该效果调用一个功能来更新ViewModel。

LaunchedEffect(key1 = Unit) {
            companyVm.getJob(index) {}
    }

我为测试发生的事情所做的只是在视图模型中更改一个值

 var job: MutableState<JobModel> = mutableStateOf(JobModel())

  fun getJob(jobPostUid: String, onComplete: () -> Unit) {

      job.value.jobTitle = "New Title"
}

时,当页面正常通过应用程序加载时,您可以看到新标题,但是当您通过深层链接加载它时,您很快就会看到它出现,然后从日志中消失并从日志中消失。我可以看到它使标题空白。

I am working on a project that uses jetpack compose and whenever i load a composable through deep links, any data that gets loaded quickly appears then goes missing.

My deep link is pretty straight forward.

composable(
                DestinationScreen.Screen.route + "/{index}",
                arguments = listOf(navArgument("index") { type = NavType.StringType }),
                deepLinks = listOf(navDeepLink { uriPattern ="pattern/job/{index}" })

            ) { entry ->
                LaunchedEffect(Unit) {
                    bottomBarState.value = false
                }
                JobDetails(navController = navController, companyVm = companyViewModel,vm, jobVm,entry.arguments?.getString("index")!!  )
            }

Inside my composable i have a launched effect that calls a function to update the viewModel.

LaunchedEffect(key1 = Unit) {
            companyVm.getJob(index) {}
    }

all i was doing to test what was happening was changing one value in the view model

 var job: MutableState<JobModel> = mutableStateOf(JobModel())

  fun getJob(jobPostUid: String, onComplete: () -> Unit) {

      job.value.jobTitle = "New Title"
}

When the page loads normally through the app you can see the new title but when you load it through a deep link you quickly see it appear then disappear and from logs i can see that it's making the title blank.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文