TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
export directive in Dart is a library-level declaration used to re-expose the public API of another library. By utilizing this directive, a library can forward the public members (classes, functions, variables, typedefs) of a specified Uniform Resource Identifier (URI) to any external library that imports it, effectively merging namespaces.
Syntax
The fundamental syntax requires theexport keyword followed by a string literal representing the URI of the target library.
Combinators
To control namespace pollution and resolve potential naming collisions, theexport directive supports combinators. These modifiers restrict exactly which members are re-exposed to the consuming library.
show(Whitelist): Restricts the export to only the explicitly declared identifiers.hide(Blacklist): Exports all public members of the target library except the explicitly declared identifiers.
Conditional Exports
Dart supports conditional exports to evaluate configuration environment constants at compile-time and dynamically determine which URI to export. The compiler evaluates theif conditions sequentially and exports the URI of the first condition that evaluates to true. If no conditions are met, it resolves the default URI declared before the conditions.
Scope and Visibility Rules
- Public Members Only: The
exportdirective strictly applies to public members. Any identifier prefixed with an underscore (_), which denotes library privacy in Dart, is inherently excluded from the export process. - Local Scope Isolation: Declaring an
exportdoes not introduce the target library’s members into the lexical scope of the exporting file. If the exporting file needs to reference those members internally, it must declare a separateimportdirective for the same URI.
- Transitive Exporting: Exports are transitive. If Library A exports Library B, and Library B exports Library C, any library importing Library A will have access to the public APIs of both Library B and Library C.
- Name Collisions: Dart strictly enforces export namespaces. If a library exports multiple URIs that contain identical public identifiers, Dart will throw an
ambiguous_exportcompile-time error directly in the file containing the conflictingexportdirectives. This error occurs immediately upon compilation, regardless of whether a consuming library attempts to use the identifier. This ambiguity must be resolved at the export level usingshoworhidecombinators to ensure a clean, unified namespace.
Master Dart with Deep Grasping Methodology!Learn More





