Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename classes with exports?

Tags:

dart

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

like image 674
Rémi Rousselet Avatar asked Jan 30 '26 16:01

Rémi Rousselet


1 Answers

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.

like image 199
Günter Zöchbauer Avatar answered Feb 01 '26 04:02

Günter Zöchbauer