Search through all our blogs and become a FlutterFlow expert in no time! We cover all things from beginner to expoert.
You are starting out with FlutterFlow and want to create an app.But where do you start? While a UI kit is a fantastic place to begin (check out our guide on getting started with a UI kit here), having a set of essential functions in your project is equally important. These functions can get really complex and project-specific, but there are also a lot of mandatory functions that every single app needs.
Every production-grade app relies on a variety of functions to perform everyday tasks. To help you kickstart your project, we’ve compiled a set of 20 essential functions that we use in every single project of ours. Having these functions implemented from the get-go will save you time and effort, allowing you to focus on the unique aspects of your app.
Let’s dive into some of the key functions included in our FFMarketplace item and explain how they work.
P.S. go here to get all 20 functions!
Converting prices to Stripe’s format is a common necessity for apps that handle payments. This function ensures that your prices are correctly formatted for Stripe.
int convertPriceForStripe(double price) {
// First, round the price to 2 decimal places
double roundedPrice = double.parse(price.toStringAsFixed(2));
// Then, convert the price to Stripe's format (cents)
int stripePrice = (roundedPrice * 100).round();
return stripePrice;
}
This function rounds a given price to two decimal places and then converts it to Stripe’s format, which is in cents. This is crucial for ensuring that the amounts are accurately processed by Stripe.
Handling date formats correctly is essential for any app. This is very useful when you want users to insert a date in the “dd/mm/yyyy” format, but you want to save it in your database as a DateTime object (this is very important!). This function converts a date string into a DateTime object.
DateTime? dateFromString(String? date) {
if (date == null) {
return null;
}
final parts = date.split('/');
if (parts.length != 3) {
throw FormatException('Invalid date format');
}
int day = int.parse(parts[0]);
int month = int.parse(parts[1]);
int year = int.parse(parts[2]);
return DateTime(year, month, day);
}
This function takes a date string in the format “dd/mm/yyyy”, splits it in today, month, and year, and then creates a DateTime object. It ensures that the input is valid and handles any potential format issues.
Often, you need to merge multiple lists of images. Whenever you want to let the user upload multiple images and you want to save that in a variable that already has images, you might notice it isn’t that simple! Using this function will solve exactly that issue. This function makes it easy to combine old and new image lists.
List<String> mergeImageLists(
List<String> oldImages,
List<String> newImages,
) {
List<String> combinedList = [];
combinedList.addAll(oldImages);
combinedList.addAll(newImages);
return combinedList;
}
This function takes two lists of image URLs (old and new), combines them into one list, and returns the merged list. This is useful for managing image galleries or any feature that involves handling multiple sets of images.
Having these functions at your disposal means you won’t have to reinvent the wheel for common tasks. They are the building blocks for more complex functionalities and will make your development process much more efficient.
These functions ensures that you have the basic necessary tools to build a robust and functional app. Whatever it is that you’re dealing with, these functions will streamline your development process and save you time.
You can integrate our comprehensive function package from theFlutterFlow Marketplace here. This package includes detailed instructions and support to help you integrate these functions seamlessly into your app.
Sed at tellus, pharetra lacus, aenean risus non nisl ultricies commodo diam aliquet arcu enim eu leo porttitor habitasse adipiscing porttitor varius ultricies facilisis viverra lacus neque.