Search⌘ K
AI Features

Optional Parameters

Explore how to use optional parameters in Dart to make your functions more flexible. Learn the differences between named and positional optional parameters, how to define them, and best practices for calling functions with optional arguments. Understand how Dart handles omitted optional parameters and how to apply these concepts in your code effectively.

We'll cover the following...

When you want to leave the passing of arguments to functions as an option, you can use optional parameters.

A function can have two types of parameters: required and optional. The required parameters are listed first, followed by any optional parameters. Optional parameters can be named or positional.

Optional parameters can either be named or positional, but not both.

Named parameters

...