> ## 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 Package Import

The `import` directive in Dart is a compilation mechanism used to bring the declarations (classes, functions, variables) of an external or internal library into the lexical scope of the current library. It relies on Uniform Resource Identifiers (URIs) to resolve and link dependencies during the compilation or interpretation phase.

Dart resolves imports using URIs, which generally fall into three categories based on the presence or absence of a URI scheme:

1. **`dart:` scheme**: Resolves to built-in Dart SDK libraries.
2. **`package:` scheme**: Resolves to external dependencies managed by the Dart package manager (`pub`) and declared in the `pubspec.yaml` file, as well as absolute imports within the current package's `lib` directory.
3. **Relative URIs (No scheme)**: Resolves to local files relative to the importing file's directory structure using standard relative path notation.

```dart theme={"dark"}
// Core SDK import (dart: scheme)
import 'dart:async';

// Package dependency import (package: scheme)
import 'package:yaml/yaml.dart';

// Relative local import (no scheme)
import '../models/user_model.dart';
```

## Namespace Prefixing

To prevent namespace collisions when multiple libraries expose identical top-level symbols, Dart provides the `as` keyword. This assigns a specific identifier (prefix) to the imported library, requiring all members of that library to be accessed through the prefix.

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

// Symbols are now scoped to the 'http' prefix
// http.Client()
```

## Combinators (Visibility Control)

Dart allows granular control over which symbols are introduced into the current namespace using combinators.

* **`show` (Allowlist)**: Imports *only* the specified symbols, ignoring the rest of the library.
* **`hide` (Blocklist)**: Imports the entire library *except* the specified symbols.

```dart theme={"dark"}
// Imports only 'max' and 'pi'
import 'dart:math' show max, pi;

// Imports everything except 'Random'
import 'dart:math' hide Random;
```

## Deferred Loading

The `deferred as` directive instructs the Dart compiler to load the library asynchronously. The library is not loaded into memory at application startup; rather, it is loaded only when the developer explicitly calls the `loadLibrary()` method on the assigned prefix.

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

Future<void> executeHeavyTask() async {
  // Explicitly load the library into memory
  await heavy.loadLibrary();
  
  // Access symbols via the prefix
  heavy.performCalculation();
}
```

## Conditional Imports

Dart supports conditional imports to substitute different library implementations at compile time based on the target platform or environment. This is achieved using the `if` keyword within the `import` directive to evaluate configuration constants (such as `dart.library.io` or `dart.library.html`). The compiler resolves the first condition that evaluates to true and ignores the rest.

```dart theme={"dark"}
import 'package:example/default_impl.dart'
    if (dart.library.io) 'package:example/io_impl.dart'
    if (dart.library.html) 'package:example/web_impl.dart';
```

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