Creating a general custom function to add numbers

Resolved

So normally if you want to create a reusable function you give it parameters to work with (or as the kids call it "dependency injection", or as I call it "basic programming principles that everyone should know")

I created a function to add numbers, it takes in a list of doubles.

double calculateTotalAmount(List<double> amounts)

I went to attach this to a Text widget so it can display a total.

Turns out I can't just give it a list of doubles from App State data, so I created another function to retrieve the App State Data.

And then I found out that Custom Functions can't read App State Data and that if you want to use App State Data then I have to hard code every single variable into the function's parameters.

I then discovered that there's a thing called Data Schema. So I thought "How about I create a schema that carries the doubles and pass that in through the text binding". After updating the Custom Function with a parameter that is the new Data Scheme Flutter Flow seemed happy with this.

So now I thought "great, now I can just pass in this Data Schema and have the values added together". I asked CoPilot to put this together and added the code to the Custom Function.

I now get an error stating that I can't access the fields in the Data Schema and that I need to import the Data Schema

'BudgetOutgoingsStruct'. Try importing the library that defines 'rent', correcting the name to the name of an existing getter, or defining a getter or field named 'rent'.

So... The question is... Is it not possible to add some numbers together without explicitly making a parameter for each number to add? And anytime I want to add some numbers I have to create a brand new Custom Function to take a specific amount of numbers because I can't just pass in a list of numbers since the data isn't accessible?

1
6 replies