Dart Anonymous Functions

In this tutorial you will learn about the Dart Anonymous Functions and its application with practical example.

Dart Anonymous Functions

In Dart, most of the functions we have seen are named functions; we can also create nameless function knows as anonymous function, lambda or closure. An anonymous function is like named function but they do not have name associated with it. An anonymous function can have zero or more parameters with optional type annotations.

Table Of Contents

An anonymous functions consists of self-contained blocks of code and that can passed around in our code as a function parameters. In Dart, we can assign an anonymous function to constants or variables, later we can access or retrieve the value of closure based on our requirements.

Syntax:-

Example:-

The above example defines an anonymous function with an untyped parameter, item. The function, invoked for each item in the list, prints a string that includes the value at the specified index. When we run the above Dart program, we will see following output.

Output:-

dart_anonymous_function_example

In this tutorial we have learn about the Dart Anonymous Functions and its application with practical example. I hope you will like this tutorial.