> ## 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 Overridden Setter

An overridden setter in Dart is a mutator method within a subclass that redefines the assignment behavior of a property inherited from a superclass. By utilizing the `@override` annotation alongside the `set` keyword, the subclass intercepts write operations directed at the property, allowing for modified assignment logic, type contravariance (or covariance via the `covariant` keyword), or delegation to the parent implementation via the `super` keyword.

## Syntax and Implementation

To override a setter, the subclass must declare a method using the `set` keyword with an identifier identical to the superclass setter.

```dart theme={"dark"}
class SuperClass {
  num _internalState = 0;

  // Base setter declaration
  set configurationValue(num value) {
    _internalState = value;
  }
}

class SubClass extends SuperClass {
  // Overridden setter declaration
  @override
  set configurationValue(num value) {
    // Delegating to the superclass setter
    super.configurationValue = value; 
  }
}
```

## Technical Constraints and Rules

1. **Signature Matching (Contravariance and Covariance):**
   By default, the parameter type of the overriding setter must be the same as, or a supertype of, the parameter type in the overridden setter. Dart's sound type system enforces this contravariance to ensure Liskov Substitution Principle (LSP) compliance. However, Dart allows you to intentionally narrow the parameter type (covariance) by using the `covariant` keyword. If the parameter in the subclass is marked `covariant` (e.g., `set configurationValue(covariant int value)`), the compiler permits the narrower type, deferring the type check to runtime.
2. **Return Type Declarations:**
   Setters in Dart inherently do not return a value. While it is syntactically valid to explicitly declare a `void` return type in the setter signature (e.g., `void set configurationValue(num value)`), the standard Dart linter rule `avoid_return_types_on_setters` strongly discourages this. The idiomatic approach is to omit the return type entirely.
3. **The `@override` Annotation:**
   While Dart allows overriding without the `@override` annotation, its use is strictly enforced by standard linting rules. It directs the analyzer to verify that a corresponding setter actually exists in the superclass hierarchy, preventing accidental shadowing if the superclass signature changes.
4. **Field to Setter Promotion:**
   In Dart, a standard instance variable implicitly generates a getter and a setter. Therefore, a subclass can override a standard, non-final field from a superclass by explicitly defining a setter. When doing so, the subclass must also override the corresponding getter. If only the setter is overridden, writing to the property updates the subclass's state, but reading from the property returns the inherited superclass field's value, leading to disjointed state.

```dart theme={"dark"}
class Base {
  // Implicitly creates a getter and setter backed by a hidden field
  String data = ""; 
}

class Derived extends Base {
  String _internalData = "";

  // Overriding the implicit getter generated by the 'data' field
  @override
  String get data => _internalData;

  // Overriding the implicit setter generated by the 'data' field
  @override
  set data(String value) {
    _internalData = value;
  }
}
```

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