Skip to main content
The parentheses pair () serves as the function application operator. It initiates the execution of a callable object—such as a function, method, closure, or callable class instance—passing any provided arguments to the defined parameters and evaluating to the return value of the invoked entity.

Syntax

The operator follows a postfix notation, placed immediately after an expression that evaluates to a callable object.
callable_expression(argument_list)
  • callable_expression: An identifier or expression resolving to a function or a class instance implementing the call method.
  • argument_list: A comma-separated list of positional or named arguments matching the callable’s signature.

Function Invocation

When applied to a function reference, the () operator triggers the execution of the function body.
String format(int id) => 'ID: $id';

// The identifier 'format' is the callable expression.
// The '()' operator invokes it with the argument 42.
final result = format(42); 

Callable Class Instances

Dart treats the () operator as syntactic sugar when applied to instances of user-defined classes. If a class defines an instance method named call, the class instance itself becomes a valid operand for the function application operator. When the () operator is applied to an object, the Dart runtime resolves this to an invocation of the object’s call method.
class HashGenerator {
  // The 'call' method enables the () operator for instances
  int call(String input) {
    return input.hashCode;
  }
}

void main() {
  final generate = HashGenerator();
  
  // Syntactic sugar: generate('data')
  // Actual execution: generate.call('data')
  final hash = generate('data'); 
}

Operator Precedence

The function application operator has extremely high precedence, binding more tightly than unary operators, multiplicative operators, or equality checks. It binds immediately to the expression on its left.
// The () operator binds to 'getFunction', executing it first.
// The result of that execution is then invoked by the second set of ().
getFunction()(); 
Master Dart with Deep Grasping Methodology!Learn More