Safeargs library doesnt generate direction class

前端 未结 19 921
孤街浪徒
孤街浪徒 2021-02-01 11:44

I use navigation library and safeargs for passing data. I define argument to fragment like that.



        
19条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 12:33

    If all the answers above didn't work for you and you are still having a problem with the directions class not being generated. Make sure you are looking for the right directions class.

    For example, we have to pass arguments from FragmentA to FragmentB.
    In the navigation graph file, we have to add the tag under FragmentB's tag. This way, we will get two generated classes FragmentBArgs and FragmentADirections. As you can see, it is the FragmentA's name who got used for the directions class created, not FragmentB.

    So, keep in mind that unlike what this question's user is looking for, the directions class generated will get the class name of the action starter fragment appended with the word "Directions". Not the destination fragment's class name (argument's owner).

    Here is what the documentation says:

    A class is created for each destination where an action originates. The name of this class is the name of the originating destination, appended with the word "Directions".

    A class is created for the receiving destination. The name of this class is the name of the destination, appended with the word "Args".

    Also, adding the argument tag under the action tag will not generate a directions class. It's used to give a different default value for the destination fragment's argument.

    Hope this helps!

提交回复
热议问题