Anton
Anton

Reputation: 2378

Named exports in dart

Is there any way to use named exports in dart? For example I have 'my_types' library with this structure:

lib
|  outside.dart
my_types
|  lib
|  |  main.dart
|  |  models.dart
|  |  repositories.dart
   

Models and repositories contains some classes:

// models.dart
abstract class ModelA {}
abstract class ModelB {}
// repositories.dart
abstract class RepositoryA {}
abstract class RepositoryB {}

In main.dart I can export this files:

// main.dart
export 'models.dart';
export 'repositories.dart';

And import them in outside.dart:

// outside.dart
import 'package:my_types/main.dart' show ModelA, RepositoryB;

class ModelAImpl implements ModelA {};
class RepositoryBImpl implements RepositoryB {};

But with a lots of classes I will end up with huge mix of classes from models, repositories and other categories.

Is it possible to do something like

// main.dart
export 'models.dart' as models; // just a pseudocode. there is no 'as' statement for exports
export 'repositories.dart' as repositories;

to be able then to import them like this and keep some structure in this mess:

import 'package:my_types/main.dart' show models, repositories;

class ModelA implements models.ModelA {};
class RepositoryB implements repositories.RepositoryB {};

Upvotes: 1

Views: 1579

Answers (1)

bharats
bharats

Reputation: 426

In dart there is no as keyword for exporting libraries. However you can control which elements to export using the show keyword.

Here's a link for reference

Upvotes: 1

Related Questions