从 jetpack HorizontalPager 中的可组合函数返回函数列表后,Gettin ComposeRuntimeError

问题描述 投票:0回答:0

我有 HorizontalPager,上面有按钮。

单击按钮后,我需要获取用户帐户。

但是点击后,函数返回账户,我得到异常:

androidx.compose.runtime.ComposeRuntimeError: Compose Runtime internal error. Unexpected or incorrect use of the Compose internal runtime API (Start/end imbalance).
.....
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock@e387db2, androidx.compose.ui.platform.MotionDurationScaleImpl@79f172, StandaloneCoroutine{Cancelling}@e05f103, AndroidUiDispatcher@f359579]
Box(modifier = modifier) {
        Column(
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            HorizontalPager(
                state = pagerState
            ) { page ->
                when (page) {
                        1 -> UserPage(
                        currentAccount,
                        onButtonClick = { onClick = it })
        }
}
.......
      if (onClick){
           val accounts: MutableList<Account?> = returnActiveAccounts(
                currentAccount = currentAccount!!,
                localBook = localBook
            ) //exception goes here
}
             

然后可组合函数返回活跃的用户帐户

@Composable
private fun returnActiveAccounts(
    currentAccount: Account,
    localBook: Factory
): MutableList<Account?> {
    val accounts = AccountManager.get(LocalContext.current).accounts
    val accountList = mutableListOf<Account?>()
    accountList.add(null)
    for (acc in accounts) {
   
        ) {
            continue
        }
        accountList.add(acc)
    }
    return accountList //here return some accounts. list not empty, no errors in this function
}
android runtime pager jetpack
© www.soinside.com 2019 - 2024. All rights reserved.