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

The `part of` directive is a structural keyword in Dart used to declare that a specific file is a subordinate component of a larger, enclosing library. It establishes a bidirectional relationship with a parent file that declares the corresponding `part` directive, allowing multiple physical files to be compiled and evaluated as a single logical library entity.

## Syntax

Modern Dart utilizes a URI-based syntax to link the subordinate file back to its parent.

```dart theme={"dark"}
// Modern URI-based syntax (Recommended)
part of 'parent_library.dart';
```

Historically, Dart used a library-name identifier. While still supported for backward compatibility, the URI approach is the standard for modern Dart development.

```dart theme={"dark"}
// Legacy library-name syntax
part of my_library_name;
```

## Technical Mechanics

When a file includes the `part of` directive, it is subject to strict compilation rules and scoping behaviors:

1. **Shared Lexical Scope:** Files connected via `part` and `part of` share the exact same library scope. This means private members (variables, classes, or functions prefixed with an underscore `_`) declared in the parent file are fully accessible within the `part of` file, and vice versa.
2. **Directive Restrictions:** A file containing a `part of` directive cannot contain its own `import`, `export`, or `library` directives. All dependencies must be resolved through the parent library file.
3. **Bidirectional Linkage:** The relationship must be explicitly defined in both directions. The parent file must declare `part 'child_file.dart';`, and the child file must declare `part of 'parent_file.dart';`. If the linkage is broken or unidirectional, the Dart analyzer will throw a compilation error.

## Code Visualization

The following demonstrates the structural relationship between a parent library and a subordinate part file.

**Parent File:** `network_module.dart`

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

// All imports must reside in the parent file
import 'dart:convert';
import 'package:http/http.dart' as http;

// Link to the subordinate file
part 'src/network_parser.dart';

// Private member accessible by the part file
String _baseUrl = "https://api.example.com";

class NetworkClient {
  void fetch() {
    // Can access members defined in the part file
    _parseResponse(); 
  }
}
```

**Subordinate File:** `src/network_parser.dart`

```dart theme={"dark"}
// Link back to the parent file using a relative URI
part of '../network_module.dart';

// No imports are allowed here

void _parseResponse() {
  // Accesses the private variable from network_module.dart
  print("Parsing data from $_baseUrl");
  
  // Accesses the dart:convert library imported in the parent
  jsonDecode('{"status": "ok"}'); 
}
```

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