Sometime we need to use the flag module in our project for flagging, also need to place the link other than the entity view page so in this case we have to generate the Flag link programmatically.
Flag module providing FlagLinkBuilder service, just consume the service and generate the link.