> For the complete documentation index, see [llms.txt](https://des-vu-technologies.gitbook.io/blogs-by-shankar/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://des-vu-technologies.gitbook.io/blogs-by-shankar/functions/functionparameters.md).

# functionParameters

```
In Dart, function parameters are used to pass values into functions.
Parameters allow you to make your functions more flexible and reusable
by accepting input data that can be used within the function's body.
Dart functions can have zero or more parameters, and each parameter has a data type and a name.
```

Here's how you define function parameters in Dart:

```dart
returnType functionName(parameter1Type parameter1Name, parameter2Type parameter2Name, ...) {
  // Function body
  // Code that uses the parameters
}
```

Let's break down the key components of function parameters in Dart:

1. **returnType**: This specifies the data type of the value that the function will return. If the function doesn't return a value, you can use `void`.
2. **functionName**: This is the name of the function.
3. **parameterType**: This is the data type of the parameter. It specifies what kind of values the parameter can accept.
4. **parameterName**: This is the name of the parameter. It is used within the function to refer to the value passed as an argument when the function is called.

Here are some examples of functions with different types of parameters in Dart:

#### Function with No Parameters:

```dart
void sayHello() {
  print('Hello, Dart!');
}
```

In this example, the `sayHello` function does not have any parameters.

#### Function with One Parameter:

```dart
void greet(String name) {
  print('Hello, $name!');
}
```

In this example, the `greet` function has one parameter of type `String` named `name`. It accepts a name as input and uses it within the function.

#### Function with Multiple Parameters:

```dart
int add(int a, int b) {
  return a + b;
}
```

In this example, the `add` function has two parameters, both of type `int`. It accepts two integers (`a` and `b`) as input, performs addition, and returns the result.

#### Function with Optional Parameters:

You can make parameters optional by enclosing them in square brackets `[]`. Optional parameters allow you to call a function without providing values for all parameters.

```dart
void printMessage(String message, [int? times]) {
  for (var i = 0; i < times ?? 1; i++) {
    print(message);
  }
}
```

In this example, the `printMessage` function has one required parameter (`message`) and one optional parameter (`times`). The `times` parameter is enclosed in square brackets, making it optional. If `times` is not provided when calling the function, it defaults to `1`.

#### Function with Named Parameters:

You can use named parameters by enclosing them in curly braces `{}`. Named parameters allow you to pass arguments to a function in any order, making function calls more expressive.

```dart
void greet({String? firstName, String? lastName}) {
  print('Hello, ${firstName ?? 'User'} ${lastName ?? ''}!');
}
```

In this example, the `greet` function has two named parameters, `firstName` and `lastName`. You can call the function with named arguments like this: `greet(firstName: 'John', lastName: 'Doe')`.

Understanding how to define and use function parameters in Dart is essential for creating flexible and versatile functions that can handle a variety of inputs.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://des-vu-technologies.gitbook.io/blogs-by-shankar/functions/functionparameters.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
