> ## 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 Part Directive

The `part` directive in Dart is a compilation mechanism that splits a single logical library across multiple physical files. When files are joined using `part` and `part of`, the Dart compiler treats them as a single contiguous entity. Consequently, all files within this relationship share the exact same **library scope**, granting them unrestricted access to each other's private members (identifiers prefixed with an underscore `_`).

## Modern Context and Style Guide

In modern Dart development, the primary application of the `part` directive is **code generation** (e.g., integrating generated files from tools like `build_runner`, `freezed`, or `json_serializable`). The official Dart style guide strongly discourages manually splitting hand-written code using `part`. For organizing hand-written code, the recommended approach is to use multiple independent libraries and expose them using `export` directives.

## Syntax and File Relationship

The implementation requires a bidirectional link between a parent library file and its subordinate part files.

**1. The Parent File (`part`)**
The parent file acts as the root of the library. It must contain all `import` and `export` directives required by any of its parts. It uses the `part` keyword followed by a relative URI string to declare its subordinate files.

```dart theme={"dark"}
// parent_library.dart
library parent_library; // Optional library declaration

import 'dart:math'; // Dependency shared with part files

// Link to the subordinate file
part 'subordinate_file.dart';

class ParentClass {
  // Private member, visible to all files in the same library scope
  final int _privateParentField = 42; 
}
```

**2. The Subordinate File (`part of`)**
The subordinate file cannot contain any `import` or `export` directives. It must begin with the `part of` directive, pointing back to the parent file. Modern Dart prefers using the parent file's URI, though referencing the parent's library name is also syntactically valid.

```dart theme={"dark"}
// subordinate_file.dart

// Points back to the parent file via URI (Preferred)
part of 'parent_library.dart'; 

// Alternatively, pointing back via library name (Legacy)
// part of parent_library;

class SubordinateClass {
  void accessParentAndDependencies() {
    final parent = ParentClass();
    
    // Direct access to the parent's private library scope
    final value = parent._privateParentField; 
    
    // Utilizing the import (dart:math) declared in the parent file
    final calculated = max(value, 100); 
    print(calculated);
  }
}
```

## Technical Constraints

* **Single Point of Entry for Dependencies:** All `import` statements required by any part file must be declared exclusively in the parent file. The Dart analyzer will throw a compilation error if an `import` is placed inside a file declared as a `part`.
* **Strict Bidirectionality:** A file declared as a `part` in a parent file must contain a corresponding `part of` directive pointing back to that specific parent. An orphaned part file cannot be compiled independently.
* **Directive Ordering:** The `part` directives must appear after all `import` and `export` directives in the parent file, but before any actual code declarations (classes, functions, variables).
* **Transitive Privacy:** Because the files are evaluated as a single library, the concept of "file-private" does not exist between them; privacy in Dart is strictly "library-private".

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