Start a Project

Dart : Callable Classes

In this article, we are going to learn about the Callable classes in Dart.

Read more about our Flutter app development services.

Introduction- Callable Classes

As the name “Callable” points out for calling something. Dart facilitates us to call the class instances like a function with the help of the Call() function.
Basically, If we want to call a class instance as a function then we need to implement the call() function in it.
The call () method supports the same functionality as normal functions such as parameters and return types.

Syntax

Implementation

Result:

Callable function example for int return type

Result:

Till now, we know about call function and how to implement them to make a class callable.
Now A question arises, Can we create multiple call functions for a class?

The answer is NO. Dart doesn’t allow us to create multiple call() functions for a class.

Let’s check it with an example.

Result:

Conclusion :

In this article, we have checked about callable classes and call() function.
Thanks for Reading.

Exit mobile version