> ## 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 Public Field

A public field in Dart is a class-level variable that is accessible from any library that imports the class. Unlike languages that rely on explicit access modifier keywords (such as `public`, `private`, or `protected`), Dart determines visibility through lexical naming conventions. Any field whose identifier does not begin with an underscore (`_`) is implicitly public.

## Syntax and Declaration

Public fields can be mutable variables, immutable variables (`final`), or class-level variables (`static`). Because Dart does not use a `public` keyword, the declaration relies solely on the type, the identifier, and optional modifiers.

```dart theme={"dark"}
class Configuration {
  // Public mutable instance field
  String environment;

  // Public immutable instance field (can only be set once)
  final String version;

  // Public static field (belongs to the class, not instances)
  static int maxConnections = 100;

  // Public late-initialized field
  late String databaseUrl;

  Configuration(this.environment, this.version);
}
```

## Technical Characteristics

**Implicit Accessors**
When you declare a public field, the Dart compiler automatically generates implicit accessor methods.

* For a mutable public field (e.g., `String environment`), Dart generates both an implicit getter and an implicit setter.
* For an immutable public field (e.g., `final String version`), Dart generates only an implicit getter.

When a developer uses dot notation (`object.field`), they are technically invoking these implicit methods rather than accessing the memory location directly. This allows you to later replace a public field with explicit getter/setter methods without breaking the API or requiring changes to the calling code.

**Library-Level Scoping**
Dart's visibility model is based on library boundaries, not class boundaries. Because a public field lacks the `_` prefix, it is exported as part of the library's public API. Any external Dart file that imports the library can read (and, if mutable, write to) the field.

**Null Safety Enforcement**
Under Dart's sound null safety, public fields must be guaranteed to have a value before they are accessed. A public field must be:

1. Initialized at the point of declaration.
2. Initialized in the constructor (via initializing formals or an initializer list).
3. Declared as nullable using the `?` operator (e.g., `String? name`).
4. Marked with the `late` keyword, deferring the initialization check to runtime.

## Access Mechanics

Accessing public fields is done using standard dot notation. Instance fields require an instantiated object, while static fields are accessed directly on the class type.

```dart theme={"dark"}
void main() {
  var config = Configuration('Production', '1.0.0');

  // Invoking the implicit setter
  config.environment = 'Staging';

  // Invoking the implicit getter
  print(config.version); 

  // Accessing a public static field via the class type
  print(Configuration.maxConnections);
}
```

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