Arrow Functions in Dart

Jay Tillu
Blogs by Jay Tillu
Published in
2 min readFeb 19, 2019
Arrow Function in Dart by Jay Tillu

Arrow Functions are a short and concise manner to represent functions in Dart. Arrow functions are also called Lambda Functions. But here remember that by using the Arrow function’s syntax you can only return one expression. It must be only one line expression. Just like a normal function, the arrow function cannot have a block of code to execute.

If your function has only one expression to return then to quickly represent it in just one line you can use the Arrow function.

Syntax

ReturnType functionName(ParameterType parameter) => expression;
  • Here also note that we don’t need a return statement explicitly.

Program

int ShowSum(int numOne, int numTwo) => numOne + numTwo;

main() {
print(ShowSum(10, 20));
}

Output
30
  • ReturnType is the type of value that the function will return.
  • functionName is the name you give to your function.
  • ParameterType is the type of the function's parameter.
  • parameter is the actual parameter value.
  • expression is the single expression that the function will evaluate and return.

Conclusion

Arrow functions are commonly used for creating inline functions and callbacks. They are particularly useful when you need to provide a single expression as the function body. Arrow functions automatically return the result of the expression without needing an explicit return keyword.

So, guys, That’s it for Arrow Functions. And as I always say Please explore it, practice it, and try to understand it conceptually.

Feel free to let me know if I miss something. Till then Keep Loving, Keep Coding. And I’ll surely catch you up in the following article.

Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitant that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

Learn More about Dart and Flutter

Follow me for more such content.

--

--

Jay Tillu
Blogs by Jay Tillu

I am Frontend Web Developer and Hobbyist Blogger. As a Web Developer, I hold expertise in HTML, CSS, JavaScript, and React.