> ## 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 Private Getter

A private getter in Dart is an accessor function prefixed with an underscore (`_`) that provides read access to a property or computed value, while restricting its visibility strictly to the library (file) in which it is declared. Because Dart enforces privacy at the library level rather than the class level, a private getter is accessible to any code within the same file, but completely hidden from external imports.

## Syntax

A private getter is defined using the `get` keyword, followed by an identifier that must begin with an underscore. It takes no parameters.

**Arrow Syntax (Expression Body):**

```dart theme={"dark"}
ReturnType get _identifier => expression;
```

**Block Syntax:**

```dart theme={"dark"}
ReturnType get _identifier {
  return expression;
}
```

## Technical Mechanics

* **Invocation:** Although declared as a function, a getter is evaluated like a standard property. It is accessed without parentheses `()`.
* **Parameterless:** By definition in the Dart language specification, getters cannot accept arguments.
* **Library-Bound Privacy:** The `_` prefix makes the getter private to the `.dart` file, not the enclosing class. If `ClassA` and `ClassB` are declared in the same file, `ClassB` can access `ClassA`'s private getters.
* **Setter Pairing:** A private getter can be paired with a private setter using the exact same identifier (e.g., `get _value` and `set _value`) to form a logically mutable private property.

## Code Visualization

The following example demonstrates the declaration and library-level scoping of a private getter:

```dart theme={"dark"}
// file: data_model.dart

class DataModel {
  final List<String> _records = ['A', 'B', 'C'];

  // Private getter using arrow syntax
  int get _recordCount => _records.length;

  // Private getter using block syntax
  String get _lastRecord {
    if (_records.isEmpty) return 'None';
    return _records.last;
  }

  void debugPrint() {
    // Accessed internally without parentheses
    print("Count: $_recordCount"); 
  }
}

// Top-level function in the SAME library (file)
void inspectData() {
  final model = DataModel();
  
  // VALID: Private getters are accessible within the same library
  print(model._recordCount); 
  print(model._lastRecord);
}
```

If the `DataModel` class above were imported into a different file, attempting to access `model._recordCount` would result in a compile-time error: `The getter '_recordCount' isn't defined for the class 'DataModel'`.

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