Skip to main content

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.

The hide combinator is a namespace-control modifier applied to import or export directives in Dart. It acts as an exclusion filter, preventing specific top-level identifiers from a target library from being introduced into the current library’s namespace, while allowing all other public identifiers to be resolved.

Syntax

The combinator is appended to the end of an import or export statement, followed by a comma-separated list of the identifiers to be excluded.
// Import all public members except ClassA and topLevelFunction
import 'package:example/example.dart' hide ClassA, topLevelFunction;

// Re-export all public members except InternalMixin
export 'package:example/example.dart' hide InternalMixin;

Mechanics and Behavior

  • Target Scope: The hide combinator strictly operates on top-level declarations (e.g., class, mixin, typedef, top-level variables, and top-level functions). It cannot be used to filter out specific instance members, static methods, or properties encapsulated within a class.
  • Namespace Resolution: When the Dart analyzer processes a directive with hide, it constructs the symbol table for the imported/exported library but explicitly drops the symbols listed in the hide clause. Attempting to reference a hidden identifier results in a compile-time Undefined name error, exactly as if the target library did not contain that declaration.
  • Export Propagation: When applied to an export directive, hide prevents the specified identifiers from being re-exported. This modifies the public API surface of the aggregating library by omitting the hidden symbols from the exported namespace.
  • Combinator Chaining: Dart allows multiple combinators (show and hide) to be chained on a single directive. When chained, the Dart compiler evaluates them sequentially from left to right.
// Evaluates left-to-right: 
// 1. Shows only ClassA, ClassB, and ClassC
// 2. Hides ClassC from that filtered subset
import 'package:example/example.dart' show ClassA, ClassB, ClassC hide ClassC;
Master Dart with Deep Grasping Methodology!Learn More