Skip to content

Instantly share code, notes, and snippets.

@mohanmanu484
Last active May 28, 2024 09:45
Show Gist options
  • Save mohanmanu484/b2ad7f7091528279987675b3047994aa to your computer and use it in GitHub Desktop.
Save mohanmanu484/b2ad7f7091528279987675b3047994aa to your computer and use it in GitHub Desktop.
class LoginScreenArg(val id: String)
class BuySellScreenArg(val ppRefId: String,
val isModifyFlow: Boolean,
val orderId: String?)
inline fun <reified T> SavedStateHandle.getArgs(): T {
return when (T::class) {
LoginScreenArg::class -> {
LoginScreenArg(id = this.get<String>("id")!!) as T
}
BuySellScreenArg::class -> {
BuySellScreenArg(
ppRefId = get<String>("ppRefId")!!,
isModifyFlow = get<Boolean>("isModifyFlow")!!,
orderId = get<String>("orderId")
) as T
}
else -> throw IllegalArgumentException("Invalid type requested")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment