> ## 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 Static Constant Field

A static constant field in Dart is a class-level variable whose value is deeply immutable and evaluated entirely at compile time. By combining the `static` and `const` modifiers, the field is bound to the class namespace rather than any specific instance, and its memory is allocated and canonicalized only once during the compilation phase.

## Syntax

```dart theme={"dark"}
class ClassName {
  static const Type fieldName = compileTimeExpression;
}
```

## Technical Characteristics

* **Compile-Time Evaluation:** The right-hand side of the assignment must be a valid constant expression. This includes literals, arithmetic operations on other constants, or invocations of `const` constructors. It cannot rely on runtime execution (e.g., `DateTime.now()` or method returns).
* **Class-Bound Access:** Because the field is `static`, it is accessed strictly through the class name (`ClassName.fieldName`). Attempting to access it through an instance of the class will result in a compilation error.
* **Deep Immutability:** The `const` modifier enforces transitive immutability. If the static constant is a collection (such as a `List`, `Set`, or `Map`) or an object instantiated via a `const` constructor, all nested elements and fields are permanently frozen.
* **Canonicalization:** Dart's compiler optimizes `const` values. If multiple static constants or variables across the application evaluate to the identical compile-time state, they point to the exact same memory reference.
* **Mandatory Static Modifier:** In Dart, an instance field cannot be `const`. Any field declared as `const` within a class must explicitly include the `static` modifier.
* **Inline Initialization:** A static constant must be initialized at the point of declaration. It cannot be initialized later in a constructor, an initializer list, or a static block.

## Code Demonstration

```dart theme={"dark"}
class SystemMetrics {
  // Primitive static constant
  static const int maxThreads = 16;

  // Computed static constant (valid because operands are constants)
  static const int threadPoolLimit = maxThreads * 2;

  // Collection static constant (deeply immutable)
  static const List<String> coreModules = ['auth', 'database', 'network'];
  
  // Object static constant (requires a const constructor)
  static const Point origin = Point(0, 0);
}

class Point {
  final int x;
  final int y;
  
  // Const constructor required for static const instantiation
  const Point(this.x, this.y); 
}

void main() {
  // Valid access via class name
  print(SystemMetrics.maxThreads);
  
  // Invalid: SystemMetrics().maxThreads (Cannot access static member via instance)
  // Invalid: SystemMetrics.maxThreads = 32 (Cannot reassign a const variable)
  // Invalid: SystemMetrics.coreModules.add('ui') (Cannot mutate a const collection)
}
```

## Type Inference

While the type can be explicitly declared, Dart's type inference allows the omission of the type annotation if it can be statically resolved from the assigned value.

```dart theme={"dark"}
class Config {
  // Type explicitly defined
  static const double timeout = 5.5; 
  
  // Type inferred as double
  static const retryDelay = 2.0; 
}
```

<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>
