Dart : Callable Classes

Updated 29 December 2023

Save

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 Classes

Callable function example for int return type

Result:

Callable Classes

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:

Callable Classes

Conclusion :

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

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home