---
title: "How do you declare optional parameters in Flutter and Dart?"
description: "Dart has optional positional parameters in square brackets and named parameters in braces. Learn defaults, required named parameters and nullable types."
url: "https://bugsee.com/answers/flutter/flutter-optional-parameter/"
---

# How do you declare optional parameters in Flutter and Dart?

Put optional positional parameters in `[ ]` and named parameters in `{ }`. Give them a default value or make them nullable, and mark named ones `required` when they must be passed.

```dart
// Optional positional
String greet(String name, [String greeting = 'Hello']) => '$greeting, $name';
greet('Ada');                 // Hello, Ada
greet('Ada', 'Welcome');      // Welcome, Ada

// Named (the usual choice for widgets)
class Badge extends StatelessWidget {
  const Badge({super.key, required this.label, this.color, this.size = 16});

  final String label;
  final Color? color;     // optional, nullable
  final double size;      // optional, with a default

  @override
  Widget build(BuildContext context) => Text(label);
}

Badge(label: 'New', size: 20);
```

Named parameters can be passed in any order and make calls self-describing. A parameter that is neither `required` nor given a default must be nullable, and you cannot mix optional positional and named parameters in the same function.

## Related questions

- [How do for loops work in Dart?](https://bugsee.com/answers/dart/dart-for-loops-made-simple-a-quick-guide/)
