원클릭으로
various-ways-to-invoke-functions-in-dart
// Discover the surprising flexibility of calling Dart functions, including mixed positional and named arguments, the `.call` operator, and dynamic invocation with `Function.apply`.
// Discover the surprising flexibility of calling Dart functions, including mixed positional and named arguments, the `.call` operator, and dynamic invocation with `Function.apply`.
Ensure that all the docs are up to date for the project.
Learn how to host PocketBase and an Astro SSR application on the same server, using PocketBase's Go integration and a reverse proxy to delegate requests to Astro for dynamic web content.
Explore how to effectively manage asynchronous data with Preact Signals by creating a custom `asyncSignal` that handles loading, error, and data states without breaking the synchronous nature of signals.
Automate your Flutter app releases to beta or production with this handy shell script that handles version bumping, formatting, cleaning, rebuilding, and deployment via Fastlane.
Learn how to create a Lit web component with CodeMirror, dynamically themed using Material Design's color utilities, for a customizable code editing experience.
Explore Dart's bitwise operations for both integers and booleans, including AND, OR (inclusive & exclusive), NAND, NOR, and XNOR, with practical code examples.
| 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"} |
There are multiple ways to call a Function 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 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 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)