Defining a Function
Explore how to write user-defined functions in Dart, understand function return types and parameters, and apply shorthand syntax for concise function expressions. This lesson prepares you to create and call functions effectively in your Dart code.
We'll cover the following...
We'll cover the following...
Writing your first function
In this chapter, we will cover user-defined functions and learn how to write our very own functions. Let’s get straight to it and look at an example of a very basic user-defined function.
Note: Ignore the Driver Code throughout this lesson.
The above function is not really of any use to us as all it does is print the statement Function Called. However, regardless of what a function does, it follows a general syntax.
Code explanation
voidis telling us that the function does not return anything. Remember when we were discussing thecontainsmethod used by collections?containsreturned a boolean value. If your function returns