In Dart, a callable class is a class that has a call method defined in it. A call method is a special method that allows you to invoke an instance of the class like a function. Callable classes are useful for creating classes that behave like functions and can be used to perform a wide range of tasks.
To allow an instance of your Dart class to be called like a function, implement the call () method.
The call () method allows an instance of any class that defines it to emulate a function. This method supports the same functionality as normal functions such as parameters and return types.
// Creating Class
class callAble {
// Defining call method which create the class callable
String call(String a, String b, String c) => 'Welcome to $a$b$c!';
}
// Main Function
void main() {
// Creating instance of class
var callInput = callAble();
// Calling the class through its instance
var callOutput = callInput('Hello ','Vinit ', 'Mepani ');
// Printing the output
print(callOutput);
}
ย