It’s very innate in Dart’s core how the call() function works. It’s very interesting. You may create a class and this class may have a function name call().
If there’s a function name call(), then you may call it from the object. Yes by using object or instance of this class.
If you create an object or instance of this class, you may pass parameter to this object. This is very odd. Not many languages provides this feature.
But this is very common in Dart language. One of the most common package in Dart Flutter is BLoC. BLoC uses this call() a lot.
Programmers usually create emit object. When they create the object actually they can pass parameter to it.
Here we see emit object for all the methods related to events and then we see we are passing parameters to emit object.
In each of the class, emit object is an instance of Emitter<T> type. In fact Emitter class has a method called call().
See the last line, we have a call() method. It takes a State object. That’s what we are passing from the BLoC class.
Let’s see another example. Here’s we used it in TDD BLoC course.
SignIn is a class, this class has a method name call(). That’s why we can do _signIn(…..). Not only that, you may also parameters inside object’s object.
In the above picture you see that we are passing SignInParams() using _signIn object. But SignInParams itself could take other parameters. This is just amazing.
You may see that on line 13, we have the call() method and it takes parameters.