- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Anonymous function in Dart Programming
A function without a name is known as an anonymous function. They behave in the exact same manner as a normal named function would. The only difference between the named and an anonymous function is how different they are in syntax.
Anonymous functions are used in Dart to form closures. An anonymous function contains a self-contained block of codes, also it can be passed as a parameter to another function as well.
Anonymous function Syntax
(parameterList){ // inner statement(s) }
Example
Now, let's consider a simple example of an anonymous function.
Consider the example shown below −
void main() { var fruits = ["Apple", "Mango", "Banana", "Kiwi"]; fruits.forEach((item) { print('${fruits.indexOf(item)}: $item'); }); }
In the above example, we have an anonymous function with an untyped parameter named item.
Output
0: Apple 1: Mango 2: Banana 3: Kiwi
- Related Articles
- Comments in Dart Programming
- Constructors in Dart Programming
- Enumerations in Dart Programming
- Functions in Dart Programming
- Immutability in Dart Programming
- Inheritance in Dart Programming
- Iterables in Dart Programming
- Lists in Dart Programming
- Loops in Dart Programming
- Maps in Dart Programming
- Methods in Dart Programming
- Mixins in Dart Programming
- Queue in Dart Programming
- Runes in Dart Programming
- Set in Dart Programming

Advertisements