How to pass parameters to callbacks in flutter?
You call widget.changePrice(childPrice);
from OneItemState
, so changePrice
can't be VoidCallback
typedef IntCallback = Function(int num);
/* ... */
class OneItem extends StatefulWidget {
OneItem(this.combo, this.index, this.changePrice);
final Combo combo;
final int index;
final IntCallback changePrice;
@override
State<StatefulWidget> createState() => OneItemState();
}
/* ... */
ViewCard(args.combo, _changeprice) // function name without braces
I would do it like this
You could declare a Function
callback, like this:
final void Function(double price) changePrice;
Here another example to understand it better:
final bool Function(String id, double price) updateItem;
bool isPriceUpdated = widget.updateItem("item1", 7.5);