title: Pass variable to void function in flutter
body: <p>I want to pass parameter from my dialouge box(Void function) to another void function but getting error </p>
  
  <blockquote>
    <p>can't be assigned to the parameter type () void flutter</p>
  </blockquote>
  
  <p>and setState also not working.</p>
  
  <p>Please check my code here:</p>
  
  <p><strong>First function</strong></p>
  
  <pre><code>  void _quantity(BuildContext context, productId,quantity){
  
      setState(() {
        productId = productId;
        quantity = quantity;
        _quantityController.text = '$quantity';
      });
      var alert = new AlertDialog(
       actions: &lt;Widget&gt;[
          FlatButton(
            child: Text("Save"),
            onPressed: _addtoCart(context, productId)
          )
        ],
      );
  
      showDialog(context: context,builder: (context) =&gt; alert);
  
    }
  </code></pre>
  
  <p><strong>Second Function:</strong></p>
  
  <pre><code>void _addtoCart(BuildContext context, productId) {
      print("Quantity: $quantity");
      print("productId: $productId");
      print("data: $data");
    }
  </code></pre>
  
  <p>Please check screenshot here</p>
  
  <p><a href="https://i.stack.imgur.com/hNXAX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/hNXAX.png" alt="enter image description here"></a></p>