Hello, community! I'm facing an issue with a custom function in FlutterFlow. My goal is to create a function that takes a list of JSON elements, filters out empty strings, and returns a list of unique, non-empty strings
Here is the code I'm using for this function:
List<String>? filterUniqueStrings(List<dynamic>? elements) {
if (elements == null || elements.isEmpty) {
print("Input list is null or empty");
return [];
}
print("Received elements: $elements");
Set<String> uniqueStrings = {};
for (var element in elements) {
print("Processing element: $element");
if (element is String) {
print("Element is a string: $element");
if (element.isNotEmpty) {
print("Adding non-empty string: $element");
uniqueStrings.add(element);
} else {
print("Skipping empty string");
}
} else {
print("Skipping non-string element: $element");
}
}
print("Unique strings: $uniqueStrings");
return uniqueStrings.toList();
}
I tested this function with the following input: ["Hello", "", "World", "Hello", "Test", ""]
Expected output: ["Hello", "World", "Test"]
Actual output: [] (empty list)
The function is configured in FlutterFlow with these settings:
Input: JSON (List<JSON>, Nullable)
Output: List<String>, Nullable
What could be the reason for this behavior? Am I missing something in the way the function is configured or implemented? Any guidance would be greatly appreciated!"