title: How to code a flutter function which runs if and only changes detected?
body: <p>I'm doing an app in flutter which has 3 flat buttons able to set values(1-3) when they pressed. Now I need a function that can print some message according to the values it received.</p>
  
  <pre><code>value == 3 ? print("happy") : print("press any button");
  value == 2 ? print("normal") : print("press any button");
  value == 1 ? print("worst") : print("press any button");
  </code></pre>
  
  <p>NOTE: onpressed function of each button can only set values. The function to detect change must be run independently somewhere which is not returning any widgets inside it. Simply onChanged() function for a group of buttons.</p>
  
  <p>For reference: </p>
  
  <pre><code>Widget flatbuttongrop(){
  return Form(
  child: Row(
    children: &lt;Widget&gt;[
       FlatButton(
              shape: CircleBorder(),
              color: Colors.red,
              child: Text("H"),
              onPressed: () {
               value = 1;
                //  return value = 1;
              },
            ),
  
             FlatButton(
              shape: CircleBorder(),
              color: Colors.yellow,
              child: Text("N"),
              onPressed: (){
              //  return value = 2;
              value = 2;
              },
            ),
  
             FlatButton(
              shape: CircleBorder(),
              color: Colors.green,
              child: Text("S"),
              onPressed: (){
                value = 3;
              },
            ),
    ],
  
  ),
  onChanged: ()
  {
    //If any flatbutton pressed then it must indicate here.
  },
    );
  
  }
  </code></pre>
  
  <p>Thanks in advance.</p>