Dart - Anonymous Functions Last Updated : 28 Mar, 2025 Comments Improve Suggest changes Like Article Like Report An anonymous function in Dart is like a named function but they do not have names associated with it. An anonymous function can have zero or more parameters with optional type annotations. An anonymous function consists of self-contained blocks of code and that can be passed around in our code as a function parameter.In Dart most of the functions are named functions we can also create nameless function knows as an anonymous function, lambda, or closure.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:(parameter_list) { statement(s)}Anonymous Function in forEach()Example: Dart // Dartprogram to illustrate // Anonymous functions in Dart void main() { var list = ["Shubham","Nick","Adil","Puthal"]; print("GeeksforGeeks - Anonymous function in Dart"); list.forEach((item) { print('${list.indexOf(item)} : $item'); }); } Output:GeeksforGeeks - Anonymous function in Dart0 : Shubham1 : Nick2 : Adil3 : PuthalThis 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. Assigning an Anonymous Function to a VariableIn Dart, functions are treated as first-class objects, allowing us to assign an anonymous function to a variable and use it like a regular function.Example: Dart void main() { // Assigning an anonymous function to a variable var multiply = (int a, int b) { return a * b; }; print(multiply(5, 3)); // Output: 15 } Output:15Using an Anonymous Function as a CallbackAnonymous functions are widely used in asynchronous operations like button clicks or API calls.Example: Dart void performOperation(int a, int b, Function operation) { print('Result: ${operation(a, b)}'); } void main() { // Passing an anonymous function performOperation(4, 2, (a, b) => a + b); } Output:Result: 6 Comment More infoAdvertise with us N nitin_sharma Follow Improve Article Tags : Dart Dart-Function Explore Dart Tutorial Dart is an open-source general-purpose programming language developed by Google. It supports application development on both the client and server side. However, it is widely used for the development of Android apps, iOS apps, IoT(Internet of Things), and web applications using the Flutter Framework 7 min read BasicsIntroduction to Dart Programming Language 4 min read Dart SDK Installation 4 min read Dart - Comments 2 min read Dart - Variables 5 min read Operators in Dart 11 min read Dart - Standard Input Output 3 min read Data TypesDart - Data Types 8 min read Basics of Numbers in Dart 6 min read Strings in Dart 6 min read Dart - Sets 6 min read Dart Programming - Map 7 min read Queues in Dart 3 min read Data Enumeration in Dart 3 min read Control FlowSwitch Case in Dart 2 min read Dart - Loops 4 min read Dart - Loop Control Statements (Break and Continue) 4 min read Labels in Dart 2 min read Key FunctionsDart - Anonymous Functions 2 min read Dart - main() Function 2 min read Dart - Common Collection Methods 2 min read How to Exit a Dart Application Unconditionally? 2 min read Dart - Getters and Setters 3 min read Dart - Classes And Objects 4 min read Object-Oriented ProgrammingDart - this keyword 2 min read Dart - Static Keyword 3 min read Dart - Super and This keyword 4 min read Dart - Concept of Inheritance 5 min read Instance and class methods in Dart 3 min read Method Overriding in Dart 3 min read Getter and Setter Methods in Dart 2 min read Abstract Classes in Dart 4 min read Dart - Builder Class 4 min read Concept of Callable Classes in Dart 4 min read Interface in Dart 3 min read Dart - extends Vs with Vs implements 4 min read Dart - Date and Time 3 min read Using await async in Dart 4 min read Dart UtilitiesHow to Combine Lists in Dart? 3 min read Dart - Finding Minimum and Maximum Value in a List 5 min read Dart - Splitting of String 1 min read Dart ProgramsDart - Sort a List 2 min read Dart - String toUpperCase() Function with Examples 1 min read Dart - Convert All Characters of a String in Lowercase 1 min read How to Replace a Substring of a String in Dart? 2 min read How to Check String is Empty or Not in Dart (Null Safety)? 1 min read Exception Handling in Dart 3 min read Assert Statements in Dart 3 min read Fallthrough Condition in Dart 3 min read Concept of Isolates in Dart 2 min read Advance ConceptsDart - Collections 7 min read Dart - Basics of Packages 2 min read Dart - String codeUnits Property 1 min read HTML Document Object Model and Dart Programming 3 min read Like