var token:String by savable("auth_token")
var age:Int by savable() /* savable("age") */
var loggedIn:Boolean by savable() /* savable("loggedIn") */
var phone by savableInt()
var name by savableString()
var timestamp by savableLong()
Note: you can pass variable key to save in shared preferences, but if you don't, it will save in variable name, for exmaple:
var username:String by savable()
var username:String by savable("name")
For update and re-save variable value in shared prefrences, just update that savable value, that's it! , for example:
var token:String by savable("auth_token")
token = "xxxxx"
var userId by savableInt()
userId = 43
data class Person(val id:Int,val name:String)
val persons:List<Person> by savable(defauleValue = emptyList())
var token:String by savable("auth_token")
var user:User by savable(defaultValue = User(id = -1,name = "empty user"))
Button(onClick = {
token = UUID.randomUUID().toString()
user = User(id = 342, name = "Iran")
}) {
Text(text = "Set")
}
Button(onClick = {
println(user.name)
Toast.makeText(context, token, Toast.LENGTH_SHORT).show()
}) {
Text(text = "Get")
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
repositories {
...
maven("https://jitpack.io")
}
dependencies {
implementation 'com.github.ehsannarmani:EasyShared:latest_version'
}
dependencies {
implementation("com.github.ehsannarmani:EasyShared:latest_version")
}