⚠️ This lesson is retired and might contain outdated information.

Define Optional Named and Positional Parameters for Functions and Methods in Dart

Jermaine Oppong
InstructorJermaine Oppong
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 2 years ago

In this lesson, we will look at the different forms of creating parameters that are optional, namely positional and named. Optional positional arguments are useful when specifying a default value for a particular parameter. Optional named parameters are useful for specifying parameter defaults and writing self-documenting functions and methods.

Instructor: [00:00] Apart from parameters that are required, functions or methods in Dart can also specify optional parameters. These come in two flavors, positioning and named. The required parameters are listed first, followed by any of the optional parameters. Optional positional parameters are defined inside opening and closing square brackets, separated by commas.

[00:29] The exclaim parameter defaults to null. Let's specify a default Boolean, and add another parameter. Optional named parameters are defined inside opening and closing curly brackets.

[00:57] Using optional named parameters will help you define functions and methods that are self-documenting. Here's how you would use these in a case of methods. Let's invoke our method. Let's refactor our method example with named parameters, update the method call, run again.

egghead
egghead
~ 23 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today