android / android/codelab-android-datastore
Type mismatch. Required: DataStore<UserPreferencesRepository.UserPreferences> Found: DataStore<Preferences>
- Dominant language
- Kotlin
- Stars
- 240
- Forks
- 113
- PR merge metrics
- No merged PRs in 30d
Description
Problem:
I followed every step mentined in the Codelab tutorial https://developer.android.com/codelabs/android-preferences-datastore?hl=zh-cn#5, but I encountered this problem"Type mismatch. Required: DataStore Found: DataStore".
TasksActivity
` viewModel = ViewModelProvider(
this,
TasksViewModelFactory(
TasksRepository,
UserPreferencesRepository(dataStore, this)
)
).get(TasksViewModel::class.java)`
UserPreferencesRepository
`class UserPreferencesRepository constructor(
private val userPreferencesStore: DataStore,
context: Context
)...
data class UserPreferences(val showCompleted: Boolean)`
Contributor guide
Research direction
Start with TasksActivity and UserPreferencesRepository, then compare their DataStore generic types with step 5 of the linked Android Preferences DataStore codelab. Reproduce the compiler error and confirm the repository constructor and call site use the same preference type so the project builds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100