I'm trying to send a product's index to a method but when i tap the button that calls the method throws me an the error the method wass called on null.
class ProductInfo extends StatelessWidget {
final index;
final Product product;
final CartModel model;
const ProductInfo({Key key, this.product, this.index, this.model}) : super(key: key);
@override
Widget build(BuildContext context) {
print(index);
return Scaffold(
appBar: AppBar(
actions: <Widget>[
IconButton(icon: Icon(Icons.shopping_cart, color: Colors.white), onPressed: () => Navigator.pushNamed(context, "ShoppingCart"))
],
),
body: SingleChildScrollView(
child: Container(
child: Column(
children: <Widget>[
images(product),
productData(product),
FlatButton(
onPressed: () => model.addProduct(ProductList(products: [index],)),
child: TextData(data: 'Agregar al carrito'),
color: fromHex('#1389fd'),
)
],
),
)
),
);
}
}