Python Libraries, Namespaces & Barrel Exports
Dart organizes code into **Libraries**. Files are connected using `import 'path/to/file.dart';`. To avoid namespace naming collisions, you can prefix imports with `as prefix`. You can filter imports with `show` (import only specific symbols) and `hide` (exclude symbols). **Barrel Files** use `export` statements to bundle and publish multiple internal library files under a single clean public import path.
"A barrel file is like a retail store catalog: instead of visiting 20 separate factory warehouses across town, you flip open one catalog that showcases all available products in one place."
Deep Dive: How It Works
`import ... as prefix`: Solves naming clashes (e.g. `import "dart:math" as math;`).
`show` / `hide`: Selectively restrict imported symbol visibility.
Barrel Files: A single `feature.dart` containing `export "src/models.dart"; export "src/views.dart";` so consumers only import one file.
Syntax Blueprint
// Import with namespace import "package:http/http.dart" as http; // Selective import import "dart:math" show pi, max; // Barrel export file export "src/user_model.dart"; export "src/user_repository.dart";
Import aliasing, symbol filtering, and library barrel exports.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Importing relative `../lib/file.dart` instead of `package:my_app/file.dart`.Why it happens: Inconsistent import paths create duplicate library instances in memory.
How to fix: Standardize on `package:` imports for all files in the `lib/` directory.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Use Math Library with Alias
Import `dart:math as math;`.
In `main()`, compute `math.pow(2, 5)` (which equals 32).
Print `2^5 = ${math.pow(2, 5)}`.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.