how to define custom functions with generic types?

Custom Code

I want to define a custom function that accepts a couple of parameters of generic type T (with an attribute productId).

What have you tried so far?

I defined the function as below, but I can't compile or save it.
bool isItemExistsInList<T extends {productId: String}>(List<T>? list, T? item) {

if (list == null || item == null) { return false; }

return list.any((element) => element.productId == item.productId);

}

Did you check FlutterFlow's Documentation for this topic?
Yes
2 replies