Skip to content

Instantly share code, notes, and snippets.

@vaibhavgoyal09
Created August 10, 2021 16:04
Show Gist options
  • Save vaibhavgoyal09/1fe32b4ba736bca21bd2295c7c8ec819 to your computer and use it in GitHub Desktop.
Save vaibhavgoyal09/1fe32b4ba736bca21bd2295c7c8ec819 to your computer and use it in GitHub Desktop.
@HiltViewModel
class DataViewModel @Inject constructor(
private val repository: DataStoreRepository
) : ViewModel() {
fun saveName(value: String) {
viewModelScope.launch {
repository.putString(NAME, value)
}
}
fun getName(): String? = runBlocking {
repository.getString(NAME)
}
fun saveAge(value: Int) {
viewModelScope.launch {
repository.putInt(AGE, value)
}
}
fun getAge(): Int? = runBlocking {
repository.getInt(AGE)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment