0

Dependency androidx.navigation:navigation-fragment-ktx:1.5.5

Fragment
override val viewModel by viewModels<CreateRequestViewModel> {
        SavedStateViewModelFactory(
            requireActivity().application, this, 
            bundleOf("groupId" to 1, "type" to "Deposit")
        )
}
Navigation Graph
<dialog
        android:id="@+id/createRequestSheet"
        android:name="com.xxx.create.CreateRequestSheet"
        tools:layout="@layout/bottom_sheet_create">
        <argument
            android:name="group_id"
            app:argType="string"
            app:nullable="false" />
       
        <deepLink
            android:id="@+id/deepLink"
            app:uri="app://request/create/args?group_id={group_id}" />

    </dialog>
ViewModel
@HiltViewModel
class CreateRequestViewModel @Inject constructor(application: Application, private val savedStateHandle: SavedStateHandle) :
    AndroidViewModel(application) {

fun getArgs(): String {
        val type = savedStateHandle.get<String>("type")
        Log.v("request Type::", type?:"")
        return type
}}

From the above codes, I defined groupId argument in nav graph and when viewModel initilize I pass two args groupId and type which should be received by savedStateHandle. It was working absolutely fine for 1.4.0 fragment lib version; however, in this version I only get groupId.

If there a bug in lib itself?

enter image description here

As I said, 1.5.5 fragment lib version have this issue, older version like 1.4.0 working fine and I get all arguments passed in bundle, well received by viewModel.

Jayesh
  • 101
  • 6

0 Answers0