Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragment has null arguments safeargs

How can I pass argument to dialog fragment using the navigation architecture component safeargs? below is my current implementation

Start Fragment

val navController = findNavController()
val action =
            QuestionListFragmentDirections.actionQuestionListFragmentToCustomDialogFragment(args.templateFlag)
        navController.navigate(
            action
        )

Destination Fragment

   args.templateFlage //supposed to return a boolean value 
   //but throws java.lang.IllegalStateException: Fragment QuestionTypeDialogFragment{e8be5e1} 
   (47b305ea-35b2-49e0-b378-d31a08ba9a41) QuestionTypeDialogFragment} has null arguments
like image 881
Ismail Avatar asked Nov 27 '19 17:11

Ismail


1 Answers

May be you use args before fragment got it. For example I changed it in my code:

 private val args by navArgs<RadioDetailFragmentArgs>()
 private val stations = args.stations.toList()

with

private val args by navArgs<RadioDetailFragmentArgs>()
private val stations by lazy {
    args.stations.toList()
}

And it works

like image 171
Pavlov Svyatoslav Avatar answered Sep 22 '22 16:09

Pavlov Svyatoslav