android - 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()
}
解决方案
Kotlin Flow 未被弃用。使用kotlinx-coroutine-android
(1.5.2) 的最新版本:org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2
这个对我有用。
推荐阅读
- java - Spring jms 在处理和确认之前将消息缓冲成批处理
- python - 如何将句子放在顶部?
- entity-framework - 如何使用 Azure 存储和实体框架上传文件
- javascript - 如何将查询 graphql 转换为 json 对象?
- python - 如何在 TF2.0 中用 GradientTape 替换 Keras 的 gradients() 函数?
- php - 多站点管理员在子目录中安装“ERR_TOO_MANY_REDIRECTS”
- postgresql - 如何使用 .bat 文件执行 postgreSql 查询
- pyspark - PySpark 超时异常
- asp.net-core - 从服务中获取类类型的可靠方法,通过 .Net Core DI 实例化
- python - 过去 2 个月的平均值