title: how pass variable from a class to another class in flutter
body: <p>I have the numOfItems set in this class and I want to use it in another class AddToCart, but I cant pass the variable successfully.. here is a sample code, please how can I do this, I cannot seem to figure it out, What I want to know is the best way to pass data after I have setState to the other class..</p>
  <pre><code>  static int numOfItems = 1;
    @override
    Widget build(BuildContext context) {
      return Row(
        children: &lt;Widget&gt;[
          buildOutlineButton(
            icon: Icons.remove,
            press: () {
              if(numOfItems &gt; 1){
                setState(() {
                  numOfItems--;
                });
              }
            },
          ),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: kDefaultPaddin / 2),
            child: Text(
              //&quot;01&quot;,
              numOfItems.toString().padLeft(2, &quot;0&quot;),
              style: Theme.of(context).textTheme.headline,
            ),
          ),
          buildOutlineButton(
              icon: Icons.add,
              press: () {
                setState(() {
                  numOfItems++;
                });
              }),
        ],
      );
    }
  
    SizedBox buildOutlineButton({IconData icon, Function press}) {
      return SizedBox(
        width: 32,
        height: 32,
        child: OutlineButton(
          padding: EdgeInsets.zero,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10),
          ),
          onPressed: press,
          child: Icon(icon),
        ),
      );
    }
  }```
  
  
  here is the second class where I want to use the numOfItems in the second class, how can I access the variable in this class.
  
  ```class AddToCart extends StatelessWidget {
    const AddToCart({
      Key key,
    }) : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      Size size = MediaQuery.of(context).size;
      return Padding(
        padding: const EdgeInsets.symmetric(vertical: kDefaultPaddin),
        child: Row(
          children: &lt;Widget&gt;[
            Container(
              margin: EdgeInsets.only(right:kDefaultPaddin),
              height:50,
              width: size.width * 0.3,
              decoration: BoxDecoration(
                border: Border.all(color:primaryColorDark),
                borderRadius: BorderRadius.circular(18),
              ),
              child: IconButton(
                icon: SvgPicture.asset(
                  &quot;assets/icons/add_to_cart.svg&quot;, color: primaryColorDark,), //svgPicture.asser
                onPressed: () {
                  // on press of the cart button
                },
              ),
            ),
            Expanded(
              child: SizedBox(
                height:50,
                child: FlatButton(
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(18)
                  ),
                  color: primaryColor,
                  onPressed: (){
                    addProductToCart(context);
  
                  },
                  child: Text(
                      &quot;Buy Now&quot;.toUpperCase(),
                      style: TextStyle(
                        fontSize: 17,
                        fontWeight: FontWeight.bold,
                        color: Colors.white,
                      )
                  ),
                ),
              ),
            )
          ],
        ),
      );
    }
  
    void addProductToCart(BuildContext context) {
     
      String quantityToSend = numOfItems
    }
  }
  }```
  
  What I want to know is the best way to pass data after I have setState to the other class.. 
  </code></pre>