Skip to main content

Custom Functions

Custom Functions in FlutterFlow allow you to perform simple Dart calculations and logic. These functions are ideal for tasks that require immediate results, such as data transformations, mathematical calculations, or simple logic operations. Custom Functions enable you to encapsulate reusable logic, making your code more organized and maintainable.

Key Use Cases

  • Data Transformation: Convert or manipulate data before displaying it in the UI.
  • Mathematical Calculations: Perform complex calculations directly within your app.
  • String Manipulation: Format or parse strings based on specific requirements.
  • Conditional Logic: Implement logic that determines output based on given inputs.

Test Functions

Custom Functions are typically straightforward input-output expressions designed to perform specific tasks. It is highly recommended to test your Custom Functions before integrating them into your project. Testing the Custom Function code ensures that it works as expected with various inputs, helping you catch potential issues early. Overall, it boosts your confidence in shipping your app to production, knowing that your logic is reliable and robust.

LOOKING for other CUSTOM Function properties?

To learn more about Custom Function properties such as Input Arguments and Return Values, please check out this comprehensive guide.

FAQs

I can't add imports!

You can't have imports in a custom function. To be able to add imports, consider using a Custom Action.

Getting error: The function 'FFAppState' isn't defined.

You can't use the app state variable (i.e., FFAppState().variablename) directly in your custom function code. Instead, you can pass the app state variable as a parameter and then use it in your code.

Some common examples

Calculating Discounts:
double calculateDiscount(double price, double discountRate) {
return price - (price * discountRate / 100);
}
String Capitalization:
String capitalize(String input) {
return input.isNotEmpty ? '${input[0].toUpperCase()}${input.substring(1)}' : '';
}
Temperature Conversion:
double celsiusToFahrenheit(double celsius) {
return (celsius * 9/5) + 32;
}