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 show combinator is a directive modifier in Dart used alongside import or export statements to act as an explicit inclusion whitelist. It restricts the visibility of an external library’s API by selectively bringing only the specified top-level declarations (classes, functions, variables, or typedefs) into the current library’s namespace, leaving all unlisted declarations inaccessible.
import 'package:library_name/library_name.dart' show DeclarationOne, declarationTwo;
export 'package:library_name/library_name.dart' show DeclarationOne;

Mechanics and Syntax Rules

  • Comma-Separated Identifiers: Multiple declarations must be separated by commas. The identifiers must exactly match the exported names from the target library.
  • Namespace Isolation: Declarations omitted from the show list are not bound in the importing library’s scope. Attempting to reference an unlisted declaration results in a static analysis error (undefined_identifier).
  • Chaining with Prefixes: The show combinator can be chained with the as directive. The filtering occurs before the prefix is applied to the namespace.
  • Export Re-routing: When used with export, the show combinator restricts which parts of an external library are re-exported as part of the current library’s public API.

Code Illustration

Given an external library arithmetic.dart:
// arithmetic.dart
int add(int a, int b) => a + b;
int subtract(int a, int b) => a - b;
int multiply(int a, int b) => a * b;
Applying the show combinator in the importing library:
// main.dart
import 'arithmetic.dart' show add, subtract;

void main() {
  print(add(5, 3));      // Valid: explicitly shown
  print(subtract(5, 3)); // Valid: explicitly shown
  
  // print(multiply(5, 3)); 
  // Error: The function 'multiply' isn't defined.
}

Combinator Chaining

When combining show with a namespace prefix (as), the syntax requires the prefix declaration to precede the combinator:
import 'arithmetic.dart' as math show add;

void main() {
  print(math.add(5, 3)); // Valid
}
Master Dart with Deep Grasping Methodology!Learn More