how to test if a node is flagged in twig
Write a function with hook preprocess_node in your custom module and set a custom variable isflagged ture or false
then check this variable in your twig file node is flagged or not 
like

/**
 * Implements hook_preprocess_node().
 */
function yourModuleName_preprocess_node(&amp;$variables) {
  $node = $variables['node']; // Just in case you need it

  if($variables['node']-&gt;getType() == "yourNodeType") {
    // your code 
    if ($flag-&gt;is_flagged ($node-&gt;id())){
      $variables['isFlagged'] = true;
    }else{
      $variables['isFlagged'] = false;
    }

  }
}


now in your twig

{% if  isFlagged %}
  //do some thing
{% endif %}


hope this helps you