Rémi Rousselet
Rémi Rousselet

Reputation: 277447

How to rename classes with exports?

I would like to make packages that do nothing besides exporting a few classes of another library under a different name.

In javascript I could do the following:

export { foo as bar } from 'package'

But I haven't found anything similar in dart

Upvotes: 3

Views: 1677

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657761

There is no such thing in Dart.

Imports allow only to show or hide members of the imported library or specify an import prefix.

I can imagine that typedefs will be extended to do that eventually.

What you can do is to create subclasses

class Dialog extends CupertinoDialog {}

and in another library

class Dialog extends MaterialDialog {}

Conditional imports might be extended at some point to allow importing one or the other library depending on some condition (probably only build-time setting).
Currently it only allows to distinguish platforms like web, server, Flutter as far as I know.

Upvotes: 2

Related Questions