Created
August 10, 2021 16:04
-
-
Save vaibhavgoyal09/1fe32b4ba736bca21bd2295c7c8ec819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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