> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dart Default Parameter

A default parameter in Dart is a compile-time constant expression assigned to an optional parameter. The Dart compiler substitutes this constant value into the function's execution context when the caller omits the corresponding argument during invocation.

Default parameters can be applied to both **named optional parameters** (enclosed in curly braces) and **positional optional parameters** (enclosed in `[]`). They cannot be applied to mandatory parameters.

## Syntax and Mechanics

The assignment operator (`=`) is used to declare a default value.

### Named Optional Parameters

When defining named parameters, the default value is specified directly after the parameter declaration.

```dart theme={"dark"}
void configureNetwork({String protocol = 'https', int timeout = 3000}) {
  print('$protocol, $timeout');
}

// Invocation
configureNetwork(); // Uses 'https' and 3000
configureNetwork(timeout: 5000); // Uses 'https' and 5000
```

### Positional Optional Parameters

For positional parameters, the default value is assigned within the square brackets. Positional optional parameters must appear after all required positional parameters.

```dart theme={"dark"}
void executeProcess(String command, [int exitCode = 0, bool force = false]) {
  print('$command, $exitCode, $force');
}

// Invocation
executeProcess('terminate'); // Uses 0 and false
executeProcess('terminate', 1); // Uses 1 and false
```

## Technical Constraints

1. **Compile-Time Constants:** Default values must be compile-time constants. You cannot use variables, instance properties, or function calls evaluated at runtime as default values.

   ```dart theme={"dark"}
   // INVALID: DateTime.now() is evaluated at runtime
   void logEvent({DateTime timestamp = DateTime.now()}) {} 

   // VALID: 'default_event' is a string literal (compile-time constant)
   void logEvent({String eventName = 'default_event'}) {}
   ```
2. **Implicit Null Default:** If an optional parameter is declared without a default value, its implicit default is `null`. Consequently, the parameter's type signature must be explicitly nullable (using the `?` suffix) to satisfy Dart's sound null safety.

   ```dart theme={"dark"}
   // 'port' defaults to null, so it must be typed as int?
   void initializeServer({int? port}) {}
   ```
3. **Collection Defaults:** When providing a default value that is a collection (like a `List`, `Set`, or `Map`), the collection literal must be explicitly marked as `const` to satisfy the compile-time constant requirement.

   ```dart theme={"dark"}
   void applyFilters({List<String> filters = const ['all', 'active']}) {}
   ```
4. **Mutual Exclusivity with `required`:** A named parameter cannot simultaneously possess a default value and the `required` modifier. The `required` keyword mandates that the caller provides an argument, rendering a fallback default value logically dead code.

   ```dart theme={"dark"}
   // INVALID: Cannot be both required and have a default
   void setThreshold({required int level = 10}) {}
   ```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Dart Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
