Lambda functions are a short and simple way to express tiny functions. Lambda functions are also known as anonymous functions or closures.They are functions without a name that can be used inline within the code.
return_type var_name = (parameters)=> expression;
Note: When using the Lambda function syntax, only one expression can be returned, and it must be a single-line expression.
// Using lambda functionfinal addNum = (int a, int b) => a + b;main() {print(addNum(15, 7));}
void main() {displayMsg();}final displayMsg = ()=>print("This is a answer on Lambda functions in Dart programming");
// Using lambda functionfinal showData = (String a, String b) => a + b;main() {print(showData("Educative ", "answer"));}
Finally, if a function only returns one expression, we may use the Lambda function to represent it in only one line.
Free Resources