首页 > 解决方案 > Flow 在 kotlinx-coroutines-android:1.5.0 中不可用?

问题描述

kotlinx.coroutines.flow.Flow不可用于 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0',但可用于 implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.0'

它被贬低了吗?什么是替代品?

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow

@Dao
interface WordDao {

    @Query("SELECT * FROM word_table ORDER BY word ASC")
    fun getAlphabetizedWords(): Flow<List<Word>>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(word: Word)

    @Query("DELETE FROM word_table")
    suspend fun deleteAll()
}

在此处输入图像描述

标签: androidkotlinkotlin-coroutines

解决方案


Kotlin Flow 未被弃用。使用kotlinx-coroutine-android(1.5.2) 的最新版本:org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2

这个对我有用。


推荐阅读