Dart Functions First Class Objects

Dart Functions First Class Objects

·

1 min read

Function as first-class objects

  • You can pass a function as a parameter to another function.

  •   void printElement(int element) {
        print(element);
      }
    
      var list = [1, 2, 3];
    
      // Pass printElement as a parameter.
      list.forEach(printElement);