java.랭.IllegalStateException:여러 개 있는 데이터 저장에 대해 활성화 같은 파일://데이터의 사용자/0/com.firstgoalkeeper.firstgoalkeeper/파일/데이터스토어/player_pref.preferences_pb. 당신이해야 하거나 유지하는 데이터 저장소로 단일이나 확인하는 없다는 것을 두 데이터 저장소의 활동에서 같은 파일(에 의해 확인하는 범위 취소).
class Constants {
companion object{
const val PLAYER_PREFERENCE = "player_pref"
val PLAYER_SELECTION_KEY = intPreferencesKey("player_selection")
}
}
abstract class PrefsDataStore(context: Context, fileName: String) {
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(
fileName
)
val mdataStore: DataStore<Preferences> = context.dataStore
}
class PlayerSelectionDataStore(context: Context) : PrefsDataStore(context,
PLAYER_PREFERENCE) {
suspend fun storeIndex(index: Int) {
mdataStore.edit {
it[PLAYER_SELECTION_KEY] = index
}
}
val userSelectionFlow: Flow<Int> = mdataStore.data.map {
it[PLAYER_SELECTION_KEY] ?: 4
}
}
@Composable
fun PlayerSelection() {
val context = LocalContext.current
val playerSelectionDataStore = PlayerSelectionDataStore(context)
var index by remember {
mutableStateOf(4)
}
Log.d("index", "PlayerSelection: we are at index ${index} ")
Log.d("index", "PlayerSelection: we select ${allTeamsLists[index].name} ")
Row(
verticalAlignment = Alignment.CenterVertically, modifier = Modifier
.fillMaxSize()
.background(color = goalkeeperBackground)
) {
// ...
Box(
modifier = Modifier
.clickable {
GlobalScope.launch {
playerSelectionDataStore.storeIndex(index)
}
Toast
.makeText(
context,
"${allTeamsLists[index].name} player is Selected ",
Toast.LENGTH_SHORT
)
.show()
}
...
) {...}
무엇을 했는지 잘못된 것이 좋습니다.