Dart

Define Dart Function

Define Dart Function

In this tutorial, we will learn how to define a Dart function. A Dart function is a block of code that performs a specific set of tasks. It can be defined by providing the function name with the appropriate parameter and return type. A function contains a set of statements known as the function body.

Define a Dart Function

The general syntax to define a function is as follows:

returnType functionName(parameterList):
{
  // code statement(s)
  return value;
}

Let’s understand the syntax of the Dart function.

returnType

The returnType is the data type of the returned value to the caller. return_type can be void, integer, double, etc. The return type must match the returned value of the function.

functionName

The function name is the name of the function. We can call the function using this name. The function name should be an appropriate and valid identifier.

parameterList

The parameterList is the list of the parameters of the function. Parameters are also called function arguments.

Code statements

Code statements are the lines of code within the function that define the operations and tasks to be performed. The code statements can include variable declarations, conditional statements, loops, and other programming constructs.

return value
The return value is the value returned by the function to the caller. The function returns the value after completing the execution.

—

Dart Tutorials

Dart tutorial on this website can be found at:

https://www.testingdocs.com/dart-tutorials-for-beginners/