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

A public method in Dart is a function bound to a class, mixin, enum, extension, or extension type that is accessible from any library that imports its defining library. Unlike many object-oriented languages, Dart does not utilize explicit access modifier keywords such as `public`, `private`, or `protected`. Instead, visibility is determined by library-level privacy based on naming conventions: all methods—including getters and setters—are implicitly public by default unless their identifier is prefixed with an underscore (`_`).

## Syntax

A public method is declared using an optional return type (which implicitly defaults to `dynamic` if omitted), an identifier (starting with a letter or a dollar sign `$`), and a parameter list enclosed in parentheses. The declaration is concluded with a method body (using a block `{}` or an arrow `=>`), or it is terminated with a semicolon (`;`) if the method is `abstract` or `external`.

Public getters and setters follow the same naming rules but use the `get` and `set` keywords. Getters omit the parameter list entirely, while setters require exactly one parameter.

```dart theme={"dark"}
abstract class NetworkClient {
  // Public instance method with explicit return type and body
  void connect(String endpoint) {
    // Implementation
  }

  // Public method with omitted return type (implicitly dynamic)
  processData(data) {
    // Implementation
  }

  // Public abstract method (no body, terminated with a semicolon)
  void disconnect();

  // Public external method (implementation provided outside Dart)
  external void nativeCall();

  // Public static method
  static bool validateConfiguration() => true;

  // Public getter (abstract)
  bool get isConnected;

  // Public setter (abstract)
  set connectionTimeout(int seconds);

  // Private method (for contrast; restricted to the defining library)
  void _initializeSocket() {
    // Implementation
  }
}

enum ConnectionState {
  connected, disconnected;
  
  // Public method on an enum
  bool isConnected() => this == ConnectionState.connected;
}
```

## Technical Characteristics

* **Implicit Visibility:** The absence of the `_` prefix is the sole mechanism for declaring a method as public. Dart compilers and analyzers treat any non-underscored method, getter, or setter as part of the public API of the enclosing declaration.
* **Library-Level Privacy:** Dart enforces encapsulation at the library level, not the class level. A public method is exposed across library boundaries, meaning it can be invoked by any external Dart file that imports the library containing the method's declaration.
* **Getters and Setters (Accessors):** Accessor methods are subject to the exact same visibility rules as standard methods. They form a fundamental part of a class's public API and implicit interface, allowing property access semantics while executing method logic.
* **Implicit Interfaces:** Every class in Dart implicitly defines an interface containing *all* of its instance members, including public methods, private methods, getters, and setters. When a class implements another class using the `implements` keyword, it must provide concrete implementations for the entire interface. Because the implicit interface includes private members, a class containing private methods cannot be fully implemented by a class residing in a different library.
* **Inheritance and Overriding:** Public instance methods defined on classes and mixins are inherited by subclasses and can be overridden using the `@override` annotation. Conversely, methods defined on `extension` and `extension type` declarations are statically resolved and cannot be overridden. When overriding a method, the signature does not need to strictly match the superclass's definition:
  * **Covariant Return Types:** Dart allows an overridden method to return a subtype of the original return type.
  * **Contravariant Parameter Types:** Dart naturally supports contravariance for parameters, allowing an overridden method to safely accept a supertype of the original parameter type without any special keywords.
  * **Covariant Parameters:** If an overridden method needs to accept a *subtype* of the original parameter type, the parameter must be explicitly marked with the `covariant` keyword.
* **Invocation:** Public instance methods are invoked on an instantiated object or value using dot notation (`instance.methodName()`). Public static methods are invoked directly on the type declaration itself (`ClassName.methodName()`). Public getters and setters are invoked using property access syntax (`instance.propertyName` and `instance.propertyName = 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>
