I want to define a custom function that accepts a couple of parameters of generic type T (with an attribute productId).
how to define custom functions with generic types?
Custom Code
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);
}
Yes
2 replies