apply static method Null safety
Dynamically call function
with the specified arguments.
Acts the same as dynamically calling function
with
positional arguments corresponding to the elements of positionalArguments
and named arguments corresponding to the elements of namedArguments
.
This includes giving the same errors if function
expects different parameters.
Example:
void printWineDetails(int vintage, {String? country, String? name}) {
print('Name: $name, Country: $country, Vintage: $vintage');
}
void main() {
Function.apply(
printWineDetails, [2018], {#country: 'USA', #name: 'Dominus Estate'});
}
// Output of the example is:
// Name: Dominus Estate, Country: USA, Vintage: 2018
If positionalArguments
is null, it's considered an empty list.
If namedArguments
is omitted or null, it is considered an empty map.
void helloWorld() {
print('Hello world!');
}
void main() {
Function.apply(helloWorld, null);
}
// Output of the example is:
// Hello world!
Implementation
external static apply(Function function, List<dynamic>? positionalArguments,
[Map<Symbol, dynamic>? namedArguments]);