I am creating a generic widget within which I want to display the SearchField
widget each time with a different return value.For example:
SearchField<String>
SearchField<CustomObject>
When every time I want to send the value of this object and display it as a return value (so that I can use it generically),
For example:
SearchField<customObjectType>
.
How can I declare the customObjectType in the widget?
2
Answers
Dart supports using generics.
Here, we use
T
as the type – as it serves as a placeholder for a type that will be specified later.It’s not clear what you aims to achieve, but here’s a parametrized generic widget: