> ## 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 Library Prefix

A Dart library prefix is an explicit lexical namespace identifier assigned to an imported library using the `as` keyword. It encapsulates the imported library's top-level members (classes, functions, variables, and typedefs) within a designated scope, requiring those members to be accessed via dot notation.

## Syntax

```dart theme={"dark"}
import 'URI' as prefix_identifier;
```

Once prefixed, members of the imported library are accessed using the `prefix_identifier.member` syntax:

```dart theme={"dark"}
import 'dart:math' as math;

final double result = math.sqrt(math.pi);
```

## Technical Mechanics

* **Namespace Binding:** By default, Dart imports declarations directly into the library namespace (or library scope) of the importing file. Applying a prefix alters this behavior, binding the library's export scope strictly to the defined identifier. A prefix is strictly a lexical namespace, not a first-class object. It cannot be assigned to variables, passed as an argument, or manipulated like an object.
* **Identifier Resolution:** When the Dart compiler encounters `prefix.identifier`, it restricts the lexical lookup for `identifier` exclusively to the scope bound to `prefix`.
* **Shared Namespaces:** Dart allows multiple libraries to be imported under the *same* prefix. Doing so merges the exported members of all those libraries into a single, shared lexical namespace.

```dart theme={"dark"}
import 'library_one.dart' as shared_prefix;
import 'library_two.dart' as shared_prefix;

void main() {
  // Members from both libraries are resolved through 'shared_prefix'
  shared_prefix.functionFromOne();
  shared_prefix.functionFromTwo();
}
```

* **Extension Resolution:** When a library containing Dart Extensions is imported with a prefix, its extension methods are hidden from implicit resolution and are no longer automatically applied to types. They must be invoked explicitly using the prefix and the extension's name.

```dart theme={"dark"}
import 'string_extensions.dart' as str_ext;

void main() {
  // Implicit resolution is disabled; this will fail:
  // 'text'.customMethod(); 

  // Explicit invocation is required:
  str_ext.StringExtension('text').customMethod();
}
```

* **Combinator Interaction:** Prefixes can be used in conjunction with `show` and `hide` combinators. The Dart analyzer applies the combinator filters to the library's API *before* binding the remaining members to the prefix namespace.

```dart theme={"dark"}
// Only the 'Random' class is bound to the 'math' prefix.
import 'dart:math' as math show Random;

void main() {
  math.Random rng = math.Random();
}
```

* **Deferred Loading Requirement:** A library prefix is syntactically mandatory when implementing deferred (lazy) loading via the `deferred as` keywords. The prefix provides the lexical namespace required to invoke the asynchronous `loadLibrary()` method, which the Dart runtime uses to load the library into memory.

```dart theme={"dark"}
import 'package:heavy_module/heavy_module.dart' deferred as heavy;

Future<void> initialize() async {
  // The prefix provides lexical access to the loadLibrary() Future
  await heavy.loadLibrary();
  heavy.executeTask();
}
```

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