Summing two textfield in another textfield.

Custom Code

Hi everyone,

I'm working on a Flutterflow app where I have a form for adding wine entries. When adding a new wine, the form includes the following text fields:

  • wineQuantity (indicating the number of bottles purchased)

  • priceSingle (indicating the price per bottle)

  • priceForAll (which should indicate the total price)

I want to automatically calculate the priceForAll based on the inputs provided in wineQuantity and priceSingle.

For example, if a user inputs:

  • wineQuantity: 2

  • priceSingle: 100

I want priceForAll to automatically update to 200.

I have used Code Pilot to create this custom function:

int? totalPriceCalculation(
  int? wineQuantity,
  int? priceSingle,
) {
  /// MODIFY CODE ONLY BELOW THIS LINE

  // Automatically calculate and update priceForAll in a form based on the inputs in wineQuantity (number of bottles) and priceSingle (price per bottle)
  int? priceForAll;
  if (wineQuantity != null && priceSingle != null) {
    priceForAll = wineQuantity * priceSingle;
  }
  return priceForAll;

  /// MODIFY CODE ONLY ABOVE THIS LINE
}

However, I haven't been able to get it to work, and I'm not sure where the issue lies.

Could anyone help me figure out what might be going wrong?

Thanks in advance!

What have you tried so far?

I've tried using Code Expression instead, but that crashed the app.

Did you check FlutterFlow's Documentation for this topic?
No
3
3 replies