Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:core
  3. Function
  4. apply static method
apply
description

apply static method

dynamicapply(
  1. Functionfunction,
  2. List?positionalArguments, [
  3. Map<Symbol,dynamic>?namedArguments
])

Dynamically callfunction with the specified arguments.

Acts the same as dynamically callingfunction withpositional arguments corresponding to the elements ofpositionalArgumentsand named arguments corresponding to the elements ofnamedArguments.

This includes giving the same errors iffunctionexpects 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

IfpositionalArguments is null, it's considered an empty list.IfnamedArguments 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,]);
  1. Dart
  2. dart:core
  3. Function
  4. apply static method
Function class

[8]ページ先頭

©2009-2025 Movatter.jp