home / skills / rodydavis / skills / dart_function-invoking
This skill explains diverse ways to invoke Dart functions, including mixed positional and named args, the .call operator, and Function.apply for dynamic calls.
npx playbooks add skill rodydavis/skills --skill dart_function-invokingReview the files below or copy the command above to add this skill to your agents.
---
name: various-ways-to-invoke-functions-in-dart
description: Discover the surprising flexibility of calling Dart functions, including mixed positional and named arguments, the `.call` operator, and dynamic invocation with `Function.apply`.
metadata:
url: https://rodydavis.com/posts/dart/function-invoking
last_modified: Tue, 03 Feb 2026 20:04:32 GMT
---
# Various Ways to Invoke Functions in Dart
There are multiple ways to call a [Function](https://dart.dev/language/functions) in Dart.
The examples below will assume the following function:
```
void myFunction(int a, int b, {int? c, int? d}) {
print((a, b, c, d));
}
```
But recently I learned that you can call a functions positional arguments in any order mixed with the named arguments. 🤯
```
myFunction(1, 2, c: 3, d: 4);
myFunction(1, c: 3, d: 4, 2);
myFunction(c: 3, d: 4, 1, 2);
myFunction(c: 3, 1, 2, d: 4);
```
In addition you can use the [`.call`](https://dart.dev/language/callable-objects) operator to invoke the function if you have a reference to it:
```
myFunction.call(1, 2, c: 3, d: 4);
```
You can also use [`Function.apply`](https://api.flutter.dev/flutter/dart-core/Function/apply.html) to dynamically invoke a function with a reference but it should be noted that it will effect js dart complication size and performance:
```
Function.apply(myFunction, [1, 2], {#c: 3, #d: 4});
```
All of these methods print the following:
```
(1, 2, 3, 4)
```
## DemoThis skill explains multiple ways to invoke functions in Dart, highlighting positional and named argument flexibility, the .call operator, and dynamic invocation with Function.apply. It shows how arguments can be mixed in surprising orders and summarizes trade-offs like code size and performance when using dynamic calls. The goal is practical guidance so you can choose the right invocation style for readability, type safety, and runtime needs.
The skill demonstrates direct invocation using positional and named parameters and shows that Dart allows mixing positional and named arguments in different orders. It covers calling a function reference via the .call method and performing dynamic invocation with Function.apply, which accepts a List of positional args and a Map of symbol keys for named args. It also points out that Function.apply can increase JavaScript compilation size and affect performance when targeting JS.
Does mixing positional and named arguments change parameter binding?
No. Mixing order does not change which values bind to which parameters; positional arguments still fill positional parameters in left-to-right order and named arguments match by name.
When should I avoid Function.apply?
Avoid it in performance-sensitive code and web builds where it can increase JS bundle size. Prefer static calls or typed Function references when possible.